@@ -10,7 +10,7 @@ import { join, relative } from "node:path";
1010import { build } from "esbuild" ;
1111import { MemoryBackend , VFS } from "../src/fs.ts" ;
1212import type { Backend } from "../src/fs.ts" ;
13- import { JVM , LM_CLASS } from "../src/jvm.ts" ;
13+ import { JVM , LM_CLASS , LM_JAR } from "../src/jvm.ts" ;
1414import { hotspot } from "./hotspot.ts" ;
1515import { NodeBackend } from "../src/node.ts" ;
1616
@@ -103,8 +103,8 @@ class Recorder implements Backend {
103103 return d ;
104104 }
105105}
106- // Runs main over the JDK through rec, with app mounted at /app.
107- async function record ( rec : Recorder , app : string , classpath : string [ ] , main : string , args : string [ ] = [ ] ) {
106+ // Runs main (a class, or a jar in LM_JAR mode) over the JDK through rec, with app mounted at /app.
107+ async function record ( rec : Recorder , app : string , classpath : string [ ] , main : string , args : string [ ] = [ ] , mode = LM_CLASS ) {
108108 const vfs = new VFS ( ) ;
109109 vfs . mount ( "/" , new MemoryBackend ( ) ) ;
110110 vfs . mount ( "/jdk" , rec ) ;
@@ -115,7 +115,7 @@ async function record(rec: Recorder, app: string, classpath: string[], main: str
115115 props : { "java.io.tmpdir" : "/tmp" , "user.home" : "/tmp" } ,
116116 stdout : ( ) => { } , stderr : ( b ) => process . stderr . write ( b ) ,
117117 } ) ;
118- const code = await vm . run ( LM_CLASS , main , args ) ;
118+ const code = await vm . run ( mode , main , args ) ;
119119 if ( code !== 0 ) throw new Error ( `${ main } exited with ${ code } ` ) ;
120120}
121121const recorder = new Recorder ( new NodeBackend ( jdk ) ) ;
@@ -134,6 +134,10 @@ javacTo("app", "-cp", join(fixtures, "lib"), join(packs, "App.java"));
134134cpSync ( join ( packs , "app.properties" ) , join ( fixtures , "app" , "app.properties" ) ) ;
135135javacTo ( "driver" , join ( packs , "Compile.java" ) ) ;
136136for ( const d of [ "lib" , "proc" , "app" ] ) execFileSync ( hotspot ( "jar" ) , [ "cf" , join ( fixtures , `${ d } .jar` ) , "-C" , join ( fixtures , d ) , "." ] ) ;
137+ // A bare start from a jar, by class name and as java -jar, reads a few more classes.
138+ execFileSync ( hotspot ( "jar" ) , [ "cfe" , join ( fixtures , "hello.jar" ) , "Hello" , "-C" , join ( dist , "samples" ) , "Hello.class" ] ) ;
139+ await record ( recorder , fixtures , [ "/app/hello.jar" ] , "Hello" ) ;
140+ await record ( recorder , fixtures , [ "/app/hello.jar" ] , "/app/hello.jar" , [ ] , LM_JAR ) ;
137141cpSync ( join ( packs , "src" ) , join ( fixtures , "src" ) , { recursive : true } ) ;
138142const appRecorder = new Recorder ( new NodeBackend ( jdk ) ) ;
139143await record ( appRecorder , fixtures , [ "/app/app.jar" , "/app/lib.jar" ] , "App" ) ;
@@ -197,7 +201,7 @@ function intersect(spans: [number, number][], within: [number, number][]): [numb
197201 }
198202 return out ;
199203}
200- // boot.pack holds what a bare start reads. app.pack, fetched the first time a
204+ // boot.pack holds what a bare start reads, from a class folder or a jar . app.pack, fetched the first time a
201205// program reads one of its parts, holds what the typical program reads beyond
202206// that and every java.base part javac reads. javac.pack holds the rest of what
203207// javac reads: the compiler's own modules.
0 commit comments