History

Implemented autotranslate feature for jvm

Dmitry Kabak (userdima committed 13 years ago

Commit 5d096501 parent 777fab22 files · +58 −2Browse files

Showing the changes to java (2 of 2 files). Show all

Unified · Split

2 files
  1. java/appl/java/classloader.b +54 −1
  2. java/appl/java/jvm.b +4 −1
java/appl/java/classloader.b+54−1
@@ -21,6 +21,9 @@ include "math.m"; · 20 unmodified lines
2121 include "hash.m";
2222 hash: Hash;
2323
24+include "sh.m";
25+ sh: Sh;
26+
2427 include "loader.m";
2528 include "classloader.m";
2629 ld: Loader;
@@ -83,6 +86,9 @@ debug: int = 0; · 56 unmodified lines
8386 verbose: int = 0;
8487 errors: int = 0;
8588
89+autotranslate := 0;
90+sysautotranslate := 0;
91+
8692 # for generating ClassLoader exceptions use
8793 # the following con's. They will be turned
8894 # into a corresponding Java Exception by
@@ -1841,6 +1847,47 @@ Class.clone(c: self ref Class, o: ref Object): ref Object · 1752 unmodified lines
18411847 # Class private methods.
18421848 #
18431849
1850+#
1851+# Autotranslation
1852+#
1853+classfilepath(path: string): string
1854+{
1855+ extlen := len ".dis";
1856+ if (len path <= extlen)
1857+ return "";
1858+ return path[:len path - extlen] + ".class";
1859+}
1860+needtranslate(disfilepath: string, classfilepath: string): int
1861+{
1862+ (derr, ddir) := sys->stat(disfilepath);
1863+ if (derr < 0)
1864+ return 1;
1865+ (cerr, cdir) := sys->stat(classfilepath);
1866+ if (cerr < 0)
1867+ return 0;
1868+
1869+ return ddir.mtime < cdir.mtime;
1870+}
1871+translate(path: string)
1872+{
1873+ classfilepath := classfilepath(path);
1874+ if (sys->open(classfilepath, Sys->OREAD) == nil)
1875+ return;
1876+ if (!needtranslate(path, classfilepath))
1877+ return;
1878+
1879+ if (sh == nil) {
1880+ sh = load Sh Sh->PATH;
1881+ if (sh == nil)
1882+ error(sys->sprint("could not load %s: %r", Sh->PATH));
1883+ }
1884+
1885+ trace(JVERBOSE, sys->sprint("Autotranslate: calling j2d for %s", classfilepath));
1886+ result := sh->run(nil, "java/j2d" :: "-g" :: "-o" :: path :: classfilepath :: nil);
1887+ if (result != "")
1888+ loaderror(classformat, result + ": " + path);
1889+}
1890+
18441891 #
18451892 # Load a class file.
18461893 #
@@ -1848,12 +1895,16 @@ Class.loadclass(c: self ref Class) · 1 unmodified line
18481895 {
18491896 c.encoding = encodename(c.name);
18501897 f := c.encoding + ".dis";
1898+ if (autotranslate)
1899+ translate(f);
18511900 m := load Nilmod f;
18521901 if (m == nil) {
18531902 e := sys->sprint("%r");
18541903 if (!matches(e, EXIST))
18551904 error(f + ": " + e);
18561905 f = ROOT + f;
1906+ if (autotranslate)
1907+ translate(f);
18571908 m = load Nilmod f;
18581909 if (m == nil) {
18591910 e = sys->sprint("%r");
@@ -3495,8 +3546,9 @@ setflags( flags : list of (string,int) ) · 1635 unmodified lines
34953546 {
34963547 if ( flags == nil ) return;
34973548
3498− for((f,v):=hd flags; flags != nil; flags = tl flags )
3549+ for(; flags != nil; flags = tl flags )
34993550 {
3551+ (f, v) := hd flags;
35003552 case (f)
35013553 {
35023554 "debug" => loadtrace();
@@ -3504,6 +3556,7 @@ setflags( flags : list of (string,int) ) · 1 unmodified line
35043556 "verbose" => loadtrace();
35053557 jtrace->level = JVERBOSE;
35063558 "warn" => warn = v;
3559+ "autotranslate" => autotranslate = 1;
35073560 }
35083561 }
35093562 }
java/appl/java/jvm.b+4−1
@@ -98,6 +98,8 @@ processargs( argv : list of string ) : (list of (string,int), list of string) · 97 unmodified lines
9898 'v' => opts = ("verbose",1)::opts;
9999 'd' => opts = ("debug",1)::opts;
100100 'w' => opts = ("warn",1)::opts;
101+ 'a' => opts = ("autotranslate",1)::opts;
102+ 's' => opts = ("sysautotranslate",1)::opts;
101103 'i' => showinfo(); #exits
102104 'h' => showhelp(jvmcmd); #exits
103105 * => mesg(sys->sprint( "error: %c is an invalid option\n", flags[x] ));
@@ -130,7 +132,8 @@ showinfo() · 26 unmodified lines
130132 showhelp(cmd:string)
131133 {
132134 mesg(sys->sprint( "usage:\t%s [-vdwih] classname classargs", cmd ));
133− mesg(sys->sprint( "\tv=verbose; d=debug; w=warnings; i=version; h=help" ));
135+ mesg(sys->sprint( "\tv=verbose; d=debug; w=warnings; i=version; \n" +
136+ "\ta=autotranslate; s=autotranslate system classes; h=help" ));
134137 exit;
135138 }
136139