History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/module (3 of 18352 files). Show all

Unified · Split

3 files
  1. java/module/cast.m +80 −0
  2. java/module/classloader.m +420 −0
  3. java/module/jni.m +690 −0
java/module/cast.m+80−0
@@ -0,0 +1,80 @@
1+#
2+# cast.m
3+#
4+# cast from JNI types to generic JNI types
5+#
6+Cast : module
7+{
8+ PATH : con "/dis/java/cast.dis";
9+
10+ # cast to JObject
11+ FromJArray : fn( ary : JNI->JArray ) : (JNI->JObject);
12+ FromJClass : fn( cl : JNI->JClass ) : (JNI->JObject);
13+ FromJString : fn( str : JNI->JString ) : (JNI->JObject);
14+
15+ # cast JArray* to JArray
16+ ByteToJArray : fn( ptr : ref JNI->ByteArray ) : (JNI->JArray);
17+ IntToJArray : fn( ptr : ref JNI->IntArray ) : (JNI->JArray);
18+ BigToJArray : fn( ptr : ref JNI->BigArray ) : (JNI->JArray);
19+ RealToJArray : fn( ptr : ref JNI->RealArray ) : (JNI->JArray);
20+ ClassToJArray : fn( ptr : ref JNI->ClassArray ) : (JNI->JArray);
21+ StringToJArray : fn( ptr : ref JNI->StringArray ) : (JNI->JArray);
22+ ObjectToJArray : fn( ptr : ref JNI->ObjectArray ) : (JNI->JArray);
23+
24+ # cast JArray to JArray*
25+ JArrayToByte : fn( ptr : JNI->JArray ) : ref JNI->ByteArray;
26+ JArrayToInt : fn( ptr : JNI->JArray ) : ref JNI->IntArray;
27+ JArrayToBig : fn( ptr : JNI->JArray ) : ref JNI->BigArray;
28+ JArrayToReal : fn( ptr : JNI->JArray ) : ref JNI->RealArray;
29+ JArrayToClass : fn( ptr : JNI->JArray ) : ref JNI->ClassArray;
30+ JArrayToString : fn( ptr : JNI->JArray ) : ref JNI->StringArray;
31+ JArrayToObject : fn( ptr : JNI->JArray ) : ref JNI->ObjectArray;
32+
33+ # cast from JObjects
34+ ToJClass : fn( obj : JNI->JObject ) : (JNI->JClass);
35+ ToJString : fn( obj : JNI->JObject ) : (JNI->JString);
36+ ToJArray : fn( obj : JNI->JObject ) : (JNI->JArray);
37+ ToJArrayB : fn( obj : JNI->JObject ) : (JNI->JArrayB);
38+ ToJArrayC : fn( obj : JNI->JObject ) : (JNI->JArrayC);
39+ ToJArrayS : fn( obj : JNI->JObject ) : (JNI->JArrayS);
40+ ToJArrayI : fn( obj : JNI->JObject ) : (JNI->JArrayI);
41+ ToJArrayJ : fn( obj : JNI->JObject ) : (JNI->JArrayJ);
42+ ToJArrayF : fn( obj : JNI->JObject ) : (JNI->JArrayF);
43+ ToJArrayD : fn( obj : JNI->JObject ) : (JNI->JArrayD);
44+ ToJArrayZ : fn( obj : JNI->JObject ) : (JNI->JArrayZ);
45+ ToJArrayJObject : fn( obj : JNI->JObject ) : (JNI->JArrayJObject);
46+ ToJArrayJString : fn( obj : JNI->JObject ) : (JNI->JArrayJString);
47+
48+ # cast for thread data
49+ JObjToJThd : fn( obj : JNI->JObject ) : (JNI->JThread);
50+ JThdToJObj : fn( jthd : JNI->JThread ) : (JNI->JObject);
51+
52+ # cast to a niladt
53+ Class2Niladt : fn( cl : JNI->ClassData ) : ref Loader->Niladt;
54+ Obj2Niladt : fn( cl : JNI->JObject ) : ref Loader->Niladt;
55+
56+ # utility
57+ JNI2Nilmod : fn( j : JNI ) : Nilmod;
58+ JArrayToHolder : fn( ary : array of JNI->JArray ) : array of JNI->JString;
59+
60+};
61+
62+Low : module
63+{
64+ PATH : con "/dis/java/low.dis";
65+
66+ SetByte : fn( ptr : ref Loader->Niladt, off : int, val : byte );
67+ SetInt : fn( ptr : ref Loader->Niladt, off : int, val : int );
68+ SetBig : fn( ptr : ref Loader->Niladt, off : int, val : big );
69+ SetReal : fn( ptr : ref Loader->Niladt, off : int, val : real );
70+ SetObj : fn( ptr : ref Loader->Niladt, off : int, val : JNI->JObject );
71+
72+ GetByte : fn( ptr : ref Loader->Niladt, off : int ) : byte;
73+ GetInt : fn( ptr : ref Loader->Niladt, off : int ) : int;
74+ GetBig : fn( ptr : ref Loader->Niladt, off : int ) : big;
75+ GetReal : fn( ptr : ref Loader->Niladt, off : int ) : real;
76+ GetObj : fn( ptr : ref Loader->Niladt, off : int ) : (JNI->JObject);
77+
78+ CallMethod : fn( mod : Nilmod, idx : int, this : JNI->JObject, args : array of ref JNI->Value, retval : ref JNI->Value );
79+
80+};
java/module/classloader.m+420−0
@@ -0,0 +1,420 @@
1+include "draw.m";
2+#
3+# Java Class Loader.
4+#
5+
6+JavaClassLoader: module
7+{
8+ PATH: con "/dis/java/classloader.dis";
9+ ROOT: con "/dis/java/java/";
10+ PROG: con "#p";
11+ LOADER: con "@Loader";
12+ CLASS: con "@Class";
13+ MP: con "@mp";
14+ ADT: con "@adt";
15+ NP: con "@np";
16+ OBJ: con "@obj";
17+ JEX: con "@jex";
18+ SYS: con "@sys";
19+ EXIST: con "does not exist";
20+ MAINFIELD: con "main";
21+ MAINSIGNATURE: con "([Ljava/lang/String;)V";
22+ VOIDSIGNATURE: con "()V";
23+ ARRAYCLASS: con "inferno/vm/Array";
24+ STRINGCLASS: con "java/lang/String";
25+ EXCEPTIONPATH: con "java/lang/";
26+ JAVAEXCEPTION: con "java ex";
27+ SPECIALINIT: con "<init>";
28+ SPECIALCLINIT: con "<clinit>";
29+ SPECIALCLONE: con "<clone>";
30+ SUXV: con '4';
31+ JAVA: con ('J'<<24)|('a'<<16)|('v'<<8)|'a';
32+ SUX: con ('S'<<24)|('u'<<16)|('x'<<8)|SUXV;
33+ NEW, HIER, RESOLVE, LOADED, INITED:
34+ con iota;
35+ MAGIC, VERSION, NAME, SUPER, INTERFACES, RELOC, DSIZE, DRELOC, CLASSREF:
36+ con (iota * 4);
37+ CMP, CADT, CNP, COBJ, CJEX, CSYS:
38+ con iota;
39+ VVAL, VMP, VNP, VOBJ: con iota;
40+ PVALUE, PEXTRA, PMETHOD, PSTATIC:
41+ con iota;
42+ WORDZ: con 4;
43+ BIGZ: con 8;
44+ MAPZ: con WORDZ * 8;
45+ STACKSIZE: con 1024;
46+ METHODOFFSET: con 2;
47+ RTCLASSOFFSET: con 1 * WORDZ;
48+ RTRELOCOFFSET: con 2 * WORDZ;
49+ RTTHISOFFSET: con 3 * WORDZ;
50+ RTFIRSTRELOC: con 4 * WORDZ;
51+ CLASSADTOFFSET: con 1 * WORDZ;
52+ MAXUNENCODED: con Sys->NAMEMAX - 7;
53+ ENCODEDLEN: con 21;
54+ RDELTA: con 16r80;
55+
56+ T_BOOLEAN: con 4;
57+ T_CHAR: con 5;
58+ T_FLOAT: con 6;
59+ T_DOUBLE: con 7;
60+ T_BYTE: con 8;
61+ T_SHORT: con 9;
62+ T_INT: con 10;
63+ T_LONG: con 11;
64+ T_OBJECT: con 12;
65+ T_ARRAY: con 13;
66+
67+ ACC_PUBLIC: con 16r0001;
68+ ACC_PRIVATE: con 16r0002;
69+ ACC_PROTECTED: con 16r0004;
70+ ACC_STATIC: con 16r0008;
71+ ACC_FINAL: con 16r0010;
72+ ACC_SUPER: con 16r0020;
73+ ACC_SYNCHRONIZED: con 16r0020;
74+ ACC_VOLATILE: con 16r0040;
75+ ACC_TRANSIENT: con 16r0080;
76+ ACC_NATIVE: con 16r0100;
77+ ACC_INTERFACE: con 16r0200;
78+ ACC_ABSTRACT: con 16r0400;
79+
80+ JCL_INTEREXT: con 16r4000;
81+ JCL_INTERWORK: con 16r8000;
82+
83+ MUSTCOMPILE: con 16r10000;
84+ DONTCOMPILE: con 16r20000;
85+
86+ Rgetputfield: con 16r1 << 16;
87+ Rgetputstatic: con 16r2 << 16;
88+ Rinvokeinterface: con 16r3 << 16;
89+ Rinvokespecial: con 16r4 << 16;
90+ Rinvokestatic: con 16r5 << 16;
91+ Rinvokevirtual: con 16r6 << 16;
92+ Rmask: con 16r7 << 16;
93+
94+ Rstaticmp: con 16r08 << 16;
95+ Rspecialmp: con 16r10 << 16;
96+
97+ POP: con 16r3 << 2; # operand
98+ PSRC: con 16r1 << 2; # patch source operand
99+ PDST: con 16r2 << 2; # destination
100+ PMID: con 16r3 << 2; # middle
101+
102+ PTYPE: con 16r3; # Operand type
103+ PIMM: con 16r0; # patch immediate operand
104+ PSIND: con 16r1; # single indirect offset
105+ PDIND1: con 16r2; # first offset of double indirect
106+ PDIND2: con 16r3; # second offset of double indirect
107+
108+ ISHIFT: con 4; # instr index shift
109+
110+ jninil: Nilmod;
111+ jnisig: int;
112+
113+ Extra: adt
114+ {
115+ what: int;
116+ class: cyclic ref Class;
117+ };
118+
119+ Field: adt
120+ {
121+ field: string;
122+ signature: string;
123+ flags: int;
124+ value: int;
125+ };
126+
127+ Method: adt
128+ {
129+ field: ref Field;
130+ class: cyclic ref Class;
131+ };
132+
133+ Patch: adt
134+ {
135+ what: int;
136+ value: int;
137+ };
138+
139+ Reloc: adt
140+ {
141+ field: string;
142+ signature: string;
143+ flags: int;
144+ patch: array of byte;
145+ };
146+
147+ RTReloc: adt
148+ {
149+ field: string;
150+ signature: string;
151+ flags: int;
152+ };
153+
154+ Interface: adt
155+ {
156+ class: cyclic ref Class;
157+ methods: array of int;
158+ };
159+
160+ Ldinfo: adt
161+ {
162+ links: array of Loader->Link;
163+ nlinks: array of Loader->Link;
164+ types: array of Loader->Typedesc;
165+ extraoffset: int;
166+ extrabase: int;
167+ extras: cyclic array of Extra;
168+ reloc: array of Patch;
169+ };
170+
171+ ClassObject: adt
172+ {
173+ mod: ref Loader->Niladt;
174+ class: cyclic ref Class;
175+ aryname: string;
176+ };
177+
178+ Object: adt
179+ {
180+ mod: ref Loader->Niladt;
181+
182+ class: fn(o: self ref Object): ref Class;
183+ };
184+
185+ Array: adt
186+ {
187+ mod: ref Loader->Niladt;
188+ holder: array of ref JavaString;
189+ dims: int;
190+ class: ref Class;
191+ primitive: int;
192+ };
193+
194+ JavaString: adt
195+ {
196+ mod: ref Loader->Niladt;
197+ str: string;
198+ };
199+
200+ JavaThrowable: adt
201+ {
202+ mod: ref Loader->Niladt;
203+ trace: array of byte;
204+ msg: ref JavaString;
205+ };
206+
207+ ThreadData: adt
208+ {
209+ BLOCKED, SUSPENDED, ACKSUSP, WAITSUSP, WAITSTOP, INTERRUPTED, EXITED, DAEMON:
210+ con (1 << iota);
211+ SHUTDOWN, BLOCK, UNBLOCK, SUSPEND, RESUME, STOP:
212+ con iota;
213+
214+ pid: int;
215+ wchan: chan of int;
216+ flags: int;
217+ ctlfile: string;
218+ control: ref Sys->FD;
219+ culprit: ref Object;
220+ this: ref Object;
221+ };
222+
223+ Class: adt
224+ {
225+ state: int;
226+ name: string;
227+ encoding: string;
228+ ownname: string;
229+ file: string;
230+ version: int;
231+ flags: int;
232+ mod: Nilmod;
233+ native: Nilmod;
234+ super: cyclic ref Class;
235+ this: cyclic ref ClassObject;
236+ info: cyclic ref Ldinfo;
237+ refs: cyclic array of ref Class;
238+ staticdata: array of ref Field;
239+ objectdata: list of ref Field;
240+ privatemethods: array of ref Field;
241+ staticmethods: array of ref Field;
242+ virtualmethods: cyclic array of Method;
243+ initmethods: array of ref Field;
244+ classinit: ref Field;
245+ cloneindex: int;
246+ interfaces: cyclic array of Interface;
247+ interindex: int;
248+ intercache: cyclic list of (ref Class, array of int);
249+ interextends: cyclic list of ref Class;
250+ interdirect: cyclic list of ref Class;
251+ objectsize: int;
252+ staticoffset: int;
253+ staticsize: int;
254+ nextra: int;
255+ dataoffset: int;
256+ datasize: int;
257+ datareloc: int;
258+ moddata: ref Loader->Niladt;
259+ modsize: int;
260+ modmap: array of byte;
261+ objmap: array of byte;
262+ objtype: int;
263+ mlinks: int;
264+
265+ loadclass: fn(c: self ref Class);
266+ resolve: fn(c: self ref Class);
267+ loadinterfaces: fn(c: self ref Class);
268+ extinterfaces: fn(c: self ref Class);
269+ linkinterfaces: fn(c: self ref Class);
270+ makeobjtype: fn(c: self ref Class);
271+ makevmtable: fn(c: self ref Class, m: list of ref Field, z: int): array of Method;
272+ relocate: fn(c: self ref Class);
273+ instrpatch: fn(c: self ref Class, i: array of Loader->Inst);
274+ modpatch: fn(c: self ref Class);
275+ getmethod: fn(c: self ref Class, f, s: string, flag: int): int;
276+ override: fn(c: self ref Class, f, s: string): int;
277+ findimethod: fn(c: self ref Class, s: string): ref Field;
278+ findpmethod: fn(c: self ref Class, f, s: string): ref Field;
279+ findsfield: fn(c: self ref Class, f: string): ref Field;
280+ findsmethod: fn(c: self ref Class, f, s: string): ref Field;
281+ findofield: fn(c: self ref Class, f: string): ref Field;
282+ findvmethod: fn(c: self ref Class, f, s: string): int;
283+ extra: fn(c: self ref Class, w, n: int, r: ref Class);
284+ extras: fn(c: self ref Class, a: array of Reloc, n: int, r: ref Class): int;
285+ special: fn(c: self ref Class, f, s: string, flags: int, r: ref Class): (int, ref Class, int);
286+ copymap: fn(c: self ref Class, m: array of byte, dr: int);
287+ copymd: fn(c: self ref Class, md: ref Loader->Niladt, dr: int, om: Nilmod);
288+ relocref: fn(c: self ref Class, t: ref Class, i: array of Loader->Inst, a: array of Reloc, x: int): int;
289+ resolvereloc: fn(c: self ref Class, r, s: string, flags: int): (int, int);
290+ addinterface: fn(c: self ref Class);
291+ getinterface: fn(c: self ref Class, k: ref Class): array of int;
292+ interlook: fn(c: self ref Class, a: array of Interface): array of int;
293+ initjni: fn(c: self ref Class);
294+ loadnative: fn(c: self ref Class);
295+
296+ # runtime entry points
297+ run: fn(c: self ref Class, args: list of string);
298+ new: fn(c: self ref Class): ref Object;
299+ call: fn(c: self ref Class, x: int, a: ref Object): ref Object;
300+ clone: fn(c: self ref Class, o: ref Object): ref Object;
301+ };
302+
303+ init: fn(j: JavaClassLoader, ctxt: ref Draw->Context);
304+ shutdown: fn();
305+ info: fn(name: string);
306+ loader: fn(name: string): ref Class;
307+ encodename: fn(name: string): string;
308+ getclass: fn(name: string): ref Class;
309+ getmodclass: fn(mod: Nilmod): ref Class;
310+ runmain: fn( j: JavaClassLoader, classname : string, argv : list of string );
311+ sysexception: fn( ex : string ) : ref Object;
312+ setflags: fn( flags : list of (string,int) );
313+
314+ # runtime entry points
315+ compatclass: fn(who, what: ref Class): int;
316+ checkcast: fn(who: ref Object, what: ref Class);
317+ instanceof: fn(who: ref Object, what: ref Class): int;
318+ acheckcast: fn(who: ref Array, what: ref Class, dims: int);
319+ ainstanceof: fn(who: ref Array, what: ref Class, dims: int): int;
320+ pcheckcast: fn(who: ref Array, what, dims: int);
321+ pinstanceof: fn(who: ref Array, what, dims: int): int;
322+ aastorecheck: fn(who: ref Object, what: ref Array);
323+ arraycopy: fn(src: ref Array, sx: int, dst: ref Array, dx: int, n: int);
324+ multianewarray: fn(ndim: int, c: ref Class, etype: int, bounds: array of int): ref Array;
325+ error: fn(s: string);
326+ delthreaddata: fn();
327+ getthreaddata: fn(): ref ThreadData;
328+ getcontext: fn(): ref Draw->Context;
329+ daemonize: fn();
330+ culprit: fn(e: string): ref Object;
331+ throw: fn(c: ref Object);
332+ rtload: fn(addr: int);
333+ getinterface: fn(c: ref Class, cookie: int): int;
334+ monitorenter: fn(o: ref Object);
335+ monitorexit: fn(o: ref Object);
336+ monitorwait: fn(o: ref Object, l: int);
337+ monitornotify: fn(o: ref Object, f: int);
338+ sleep: fn(l: int);
339+ interrupt: fn(t: ref ThreadData);
340+ suspend: fn(t: ref ThreadData);
341+ resume: fn(t: ref ThreadData);
342+ stop: fn(t: ref ThreadData, o: ref Object);
343+
344+ # math
345+ lcmp: fn(x: big, y: big): int;
346+
347+ d2i: fn(x: real): int;
348+ d2l: fn(x: real): big;
349+ dcmpg: fn(x, y: real): int;
350+ dcmpl: fn(x, y: real): int;
351+ drem: fn(x, y: real): real;
352+};
353+
354+JavaNative: module
355+{
356+ PATH: con "/dis/java/javanative.dis";
357+
358+ init: fn(sys: Sys, ld: Loader, jldr: JavaClassLoader, jass: JavaAssist): string;
359+};
360+
361+JavaAssist: module
362+{
363+ PATH: con "/dis/java/javaassist.dis";
364+
365+ getint: fn(mod: Nilmod, index: int): int;
366+ getbytearray: fn(mod: Nilmod, index: int): array of byte;
367+ getintarray: fn(mod: Nilmod, index: int): array of int;
368+ getstrarray: fn(mod: Nilmod, index: int): array of string;
369+ getptr: fn(mod: Nilmod, index: int): ref Loader->Niladt;
370+ getreloc: fn(mod: Nilmod, index: int): array of JavaClassLoader->Reloc;
371+ getrtreloc: fn(data: ref Loader->Niladt, index: int): array of JavaClassLoader->RTReloc;
372+ getclassadt: fn(data: ref Loader->Niladt, index: int): ref JavaClassLoader->Class;
373+ getabsint: fn(addr: int): int;
374+ getadtstring: fn(data: ref Loader->Niladt, index: int): string;
375+ getstring: fn(mod: Nilmod, index: int): string;
376+ putclass: fn(data: ref Loader->Niladt, index: int, value: ref JavaClassLoader->Class);
377+ putint: fn(data: ref Loader->Niladt, index: int, value: int);
378+ putmod: fn(data: ref Loader->Niladt, index: int, value: Nilmod);
379+ putobj: fn(data: ref Loader->Niladt, index: int, value: ref JavaClassLoader->ClassObject);
380+ putptr: fn(data: ref Loader->Niladt, index: int, value: ref Loader->Niladt);
381+ putstring: fn(data: ref Loader->Niladt, index: int, value: string);
382+ little_endian: fn(): int;
383+ jclnilmod: fn(j: JavaClassLoader): Nilmod;
384+ sysnilmod: fn(s: Sys): Nilmod;
385+ new: fn(mod: Nilmod, index: int): ref JavaClassLoader->Object;
386+ getobjclass: fn(j: ref JavaClassLoader->Object): ref JavaClassLoader->Class;
387+ modhash: fn(mod: Nilmod): int;
388+ objhash: fn(j: ref JavaClassLoader->Object): int;
389+ mcall0: fn(mod: Nilmod, index: int): int;
390+ mcall1: fn(mod: Nilmod, index: int, arg: ref JavaClassLoader->Object): ref JavaClassLoader->Object;
391+ mcalla: fn(mod: Nilmod, index: int, arg: ref JavaClassLoader->Array): int;
392+ mcallm: fn(mod: Nilmod, index: int, arg: Nilmod): int;
393+ getmd: fn(mod: Nilmod): ref Loader->Niladt;
394+ arrayof: fn(o: ref JavaClassLoader->Object): ref JavaClassLoader->Array;
395+ bytearraytoJS: fn(a: array of byte): array of ref JavaClassLoader->JavaString;
396+ intarraytoJS: fn(a: array of int): array of ref JavaClassLoader->JavaString;
397+ bigarraytoJS: fn(a: array of big): array of ref JavaClassLoader->JavaString;
398+ realarraytoJS: fn(a: array of real): array of ref JavaClassLoader->JavaString;
399+ ArraytoJS: fn(a: ref JavaClassLoader->Array): ref JavaClassLoader->JavaString;
400+ JStoObject: fn(j: ref JavaClassLoader->JavaString): ref JavaClassLoader->Object;
401+ ObjecttoJT: fn(o: ref JavaClassLoader->Object): ref JavaClassLoader->JavaThrowable;
402+ makeadt: fn(addr: int): ref Loader->Niladt;
403+};
404+
405+JavaTrace: module
406+{
407+ PATH: con "/dis/java/javatrace.dis";
408+
409+ JVERBOSE,
410+ JDEBUG: con iota;
411+
412+ init: fn(a: JavaAssist);
413+ info: fn(c: ref JavaClassLoader->Class);
414+ pr_reloc: fn(r: JavaClassLoader->Reloc);
415+ pr_relocs: fn(r: array of JavaClassLoader->Reloc);
416+ trace: fn(c: int, s: string);
417+
418+ level: int;
419+ outfd: ref Sys->FD;
420+};
java/module/jni.m+690−0
@@ -0,0 +1,690 @@
1+#
2+# jni -- java native interface
3+#
4+# this module defines the limbo helper
5+# functions for java class library
6+# native methods (limbo).
7+#
8+# This module is based on the JNI
9+# specification from JavaSoft for
10+# VM implementations supporting a C/C++
11+# interface.
12+#
13+
14+include "sys.m";
15+include "math.m";
16+include "string.m";
17+include "loader.m";
18+include "classloader.m";
19+include "cast.m";
20+
21+JNI : module
22+{
23+ # where to find jni.dis
24+ PATH : con "/dis/java/jni.dis";
25+
26+ #
27+ # exported read-only vars
28+ # upon JNI initialization the following
29+ # variables are assigned. Native method modules
30+ # can use the following instances rather than
31+ # loading their own copies. These variables
32+ # should never be assigned.
33+ sys : Sys; # std inferno sys module
34+ math : Math; # std inferno math module
35+ str : String; # std inferno string module
36+ jldr : JavaClassLoader; # primary java class loader
37+ jassist : JavaAssist; # java assist module
38+
39+ # boolean constants
40+ FALSE : con 0;
41+ TRUE : con 1;
42+ BFALSE : con byte 0;
43+ BTRUE : con byte 1;
44+
45+ # return error flags for JNI functions
46+ OK : con 0;
47+ ERR : con -1;
48+
49+ # JVM Type Constants: used for identifying Java primitive types.
50+ T_JVMSTART : con 4;
51+ T_BOOLEAN, T_CHAR, T_FLOAT, T_DOUBLE, T_BYTE, T_SHORT,
52+ T_INT, T_LONG, T_OBJECT, T_ARRAY, T_VOID,
53+ T_JVMLAST
54+ : con (iota + T_JVMSTART);
55+
56+ # JVM class flags constants
57+ ACC_PUBLIC: con 16r0001;
58+ ACC_PRIVATE: con 16r0002;
59+ ACC_PROTECTED: con 16r0004;
60+ ACC_STATIC: con 16r0008;
61+ ACC_FINAL: con 16r0010;
62+ ACC_SUPER: con 16r0020;
63+ ACC_SYNCHRONIZED: con 16r0020;
64+ ACC_VOLATILE: con 16r0040;
65+ ACC_TRANSIENT: con 16r0080;
66+ ACC_NATIVE: con 16r0100;
67+ ACC_INTERFACE: con 16r0200;
68+ ACC_ABSTRACT: con 16r0400;
69+
70+ ACC_WRITTEN_FLAGS: con 16r0fff;
71+
72+
73+ # common java types
74+
75+ #
76+ # The following two types are used to represent
77+ # Java classes. The 'ClassData' type contains all
78+ # of the information pertaining to a class and is
79+ # used to obtain class information and instantiate
80+ # objects. Although there is information in the
81+ # structure it should normally be treated as an
82+ # opaque type by client native method modules.
83+ #
84+ ClassModule : type ref Loader->Niladt;
85+ ClassData : type ref JavaClassLoader->Class;
86+
87+ #
88+ # This is the "generic" type of any Java instance.
89+ # Operations on the object can be performed via this
90+ # generic handle.
91+ #
92+ JObject : type ref JavaClassLoader->Object;
93+
94+ #
95+ # This represents an instance of java.lang.Class
96+ # It is an object which contains a ptr to the
97+ # actual class data it represents.
98+ #
99+ JClass : type ref JavaClassLoader->ClassObject;
100+
101+ #
102+ # This is an instance of java.lang.String.
103+ # This class is a wrapper of a Dis string.
104+ #
105+ JString : type ref JavaClassLoader->JavaString;
106+
107+ JBoolean : type int;
108+
109+ # Java arrays are actually classes
110+ # which wrap a Dis array. The array
111+ # class matches the adt 'Array' defined
112+ # in JavaClassLoader. The following arrays
113+ # should mirror that adt and are used by
114+ # limbo modules to access the array contents
115+ # directly. Java Arrays should only be created
116+ # in Java code or via the Array functions
117+ # below. A simple limbo instance of the
118+ # array adt's is not good enough.
119+
120+ # JArray is used as a "generic" array and to represent
121+ # multi-dimensional arrays.
122+ JArray : type ref JavaClassLoader->Array; # x[][]..
123+
124+ IntArray : adt
125+ {
126+ cl_mod: ref Loader->Niladt; # object's class data
127+ ary: array of int; # actual dis array
128+ dims: int; # number of dimensions
129+ class: ClassData; # class data of base type
130+ primitive: int; # set if base type is primitive
131+ };
132+
133+ ByteArray : adt
134+ {
135+ cl_mod: ref Loader->Niladt; # object's class data
136+ ary: array of byte; # actual dis array
137+ dims: int; # number of dimensions
138+ class: ClassData; # class data of base type
139+ primitive: int; # set if base type is primitive
140+ };
141+
142+ BigArray : adt
143+ {
144+ cl_mod: ref Loader->Niladt; # object's class data
145+ ary: array of big; # actual dis array
146+ dims: int; # number of dimensions
147+ class: ClassData; # class data of base type
148+ primitive: int; # set if base type is primitive
149+ };
150+
151+ RealArray : adt
152+ {
153+ cl_mod: ref Loader->Niladt; # object's class data
154+ ary: array of real; # actual dis array
155+ dims: int; # number of dimensions
156+ class: ClassData; # class data of base type
157+ primitive: int; # set if base type is primitive
158+ };
159+
160+ StringArray : adt
161+ {
162+ cl_mod: ref Loader->Niladt; # object's class data
163+ ary: array of JString; # actual dis array
164+ dims: int; # number of dimensions
165+ class: ClassData; # class data of base type
166+ primitive: int; # set if base type is primitive
167+ };
168+
169+ ClassArray : adt
170+ {
171+ cl_mod: ref Loader->Niladt; # object's class data
172+ ary: array of JClass; # actual dis array
173+ dims: int; # number of dimensions
174+ class: ClassData; # class data of base type
175+ primitive: int; # set if base type is primitive
176+ };
177+
178+ ObjectArray : adt
179+ {
180+ cl_mod: ref Loader->Niladt; # object's class data
181+ ary: array of JObject; # actual dis array
182+ dims: int; # number of dimensions
183+ class: ClassData; # class data of base type
184+ primitive: int; # set if base type is primitive
185+ };
186+
187+ ArrayArray : adt
188+ {
189+ cl_mod: ref Loader->Niladt; # object's class data
190+ ary: array of JArray; # actual dis array
191+ dims: int; # number of dimensions
192+ class: ClassData; # class data of base type
193+ primitive: int; # set if base type is primitive
194+ };
195+
196+ #
197+ # Common type names emitted by 'javal'.
198+ #
199+ JArrayI : type ref IntArray; # int[]
200+ JArrayC : type ref IntArray; # char[]
201+ JArrayB : type ref ByteArray; # byte[]
202+ JArrayS : type ref IntArray; # short[]
203+ JArrayJ : type ref BigArray; # long[]
204+ JArrayF : type ref RealArray; # float[]
205+ JArrayD : type ref RealArray; # double[]
206+ JArrayZ : type ref ByteArray; # boolean[]
207+
208+ JArrayJClass : type ref ClassArray; # Class[]
209+ JArrayJString : type ref StringArray; # String[]
210+ JArrayJObject : type ref ObjectArray; # Object[]
211+
212+ ThreadObject : adt
213+ {
214+ cl_mod : ClassModule;
215+ name : JArrayC;
216+ priority : int;
217+ #threadQ : cyclic ref ThreadObject;
218+ PrivateInfo : ref JavaClassLoader->ThreadData;
219+ was_interrupted : byte; #boolean
220+ #eetop : int;
221+ #single_step : byte; #boolean
222+ daemon : byte; #boolean
223+ stillborn : byte; #boolean
224+ target : JObject;
225+ group : JObject;
226+ #initial_stack_memory : int;
227+ };
228+ JThread : type ref ThreadObject;
229+
230+
231+ #
232+ # This union type is used for setting/getting fields
233+ # of an arbitrary Java object/class, and also for
234+ # calling arbitrary object/class methods.
235+ # To set Java reference types (i.e. objects, arrays)
236+ # they must be converted to a JObject (i.e. use TObject).
237+ #
238+ # One way to create an instance of this type is:
239+ # val := ref Value.TObject(obj);
240+ #
241+ # To retrieve a value use a 'pick' statement or one
242+ # of the "getter" functions below.
243+ #
244+ # NOTE: the Low module is aware of the order of the "pick" tags
245+ #
246+ Value :adt
247+ {
248+ pick
249+ {
250+ TObject => jobj : JObject;
251+ TByte => jbyte : int;
252+ TBoolean => jboolean: int;
253+ TChar => jchar : int;
254+ TShort => jshort : int;
255+ TInt => jint : int;
256+ TLong => jlong : big;
257+ TFloat => jfloat : real;
258+ TDouble => jdouble : real;
259+ }
260+
261+ #
262+ # Get a value of the expected type. If the
263+ # actual type is not the expected type then
264+ # a FatalError() is called.
265+ #
266+ Boolean : fn( this : self ref Value ) : JBoolean;
267+ Byte : fn( this : self ref Value ) : int;
268+ Short : fn( this : self ref Value ) : int;
269+ Int : fn( this : self ref Value ) : int;
270+ Long : fn( this : self ref Value ) : big;
271+ Float : fn( this : self ref Value ) : real;
272+ Double : fn( this : self ref Value ) : real;
273+ Char : fn( this : self ref Value ) : int;
274+ Object : fn( this : self ref Value ) : JObject;
275+
276+
277+ };
278+
279+ #
280+ # This structure is used to "describe" a Java type. A Java signature
281+ # stored as a string is converted into this ADT for better comparisons.
282+ # Depending on the actual type vairous parts of the ADT will be filled
283+ # in. The 'sig' field will contain the appropriate java signagure string
284+ # associated with the type. The following details how to distinguish the
285+ # type:
286+ # non-array ref:
287+ # 'class' represents the class info; other fields are 0/nil
288+ # array ref:
289+ # "class" is nil for primitive array and 'prim' contains one of
290+ # the "Java Type Constants" representing the array's base type.
291+ # for non-primitive arrays 'class' is the ClassData for the base
292+ # type; 'prim' is 0; 'dims' contains the number of dimensions
293+ # primitive:
294+ # 'class' is nil; 'dims' is 0; 'prim' is one of Java Type Consts
295+ # method:
296+ # 'params' is a list of Descriptor's for each param -- nil if the
297+ # method has no parameters. The method return value is represented
298+ # by the other fields as described above; a method w/ no return
299+ # value will have (nil,T_VOID,0,"V",nil) descriptor. NOTE: the param
300+ # list is in (Right-to-Left order -- i.e right most param is the
301+ # list-head).
302+ #
303+ Descriptor : adt
304+ {
305+ class : ClassData;
306+ prim : int;
307+ dims : int;
308+ sig : string; #type's java signature
309+ params : cyclic list of ref Descriptor;
310+ };
311+
312+
313+ #
314+ # argument passed to AttachCurrentThread
315+ #
316+ ThreadAttachArgs : adt
317+ {
318+ name : string; #can be nil
319+ daemon : byte; #1=true
320+ group : JObject; #nil ==> main group
321+ };
322+
323+
324+ #
325+ # JNI Functions
326+ #
327+
328+ #
329+ # Return JNI version number in the form
330+ # of 0xVVVVIIII where VVVV=major version
331+ # and IIII= minor version
332+ #
333+ GetVersion : fn() : int;
334+
335+
336+ ##
337+ ## Class/Object access
338+ ##
339+
340+ #
341+ # Find the class data for a given class name.
342+ # Will cause a load of the class if necessary.
343+ # NOTE: this does not return a java.lang.Class
344+ # object, but rather the internal structure.
345+ #
346+ FindClass : fn( name : string ) : ClassData;
347+
348+ #
349+ # Return the class's superclass data.
350+ #
351+ GetSuperclass : fn( cl_data : ClassData ) : ClassData;
352+
353+ #
354+ # Return the java.lang.Class instance associated
355+ # with this instance.
356+ #
357+ GetObjectClass : fn( obj : JObject ) : JClass;
358+
359+ #
360+ # Return the internal Class Data information
361+ # associated with this instance
362+ #
363+ GetObjectClassData : fn( obj : JObject ) : ClassData;
364+
365+ #
366+ # return the associated java.lang.Class instance
367+ # associated with the given internal Class
368+ # Data.
369+ #
370+ GetClassObject : fn( cl_data : ClassData ) : JClass;
371+
372+ #
373+ # return the java.lang.Class instance associated
374+ # with the array class that has signature 'sig'.
375+ #
376+ LookupArrayClass : fn( sig : string ) : JClass;
377+
378+ #
379+ # Allocate an instance of java.lang.Class that
380+ # represents the class indicated by 'cl_data'.
381+ # The 'cl_data' can be obtained via the functions above.
382+ #
383+ NewClassObject : fn( cl_data : ClassData ) : JClass;
384+
385+ #
386+ # Allocate a new instance of the class; no constructor called.
387+ #
388+ AllocObject : fn( cl_data : ClassData ) : JObject;
389+
390+ #
391+ # Allocate a new instance of the class and
392+ # attempt to call the "default" constructor.
393+ # NOTE: this routine should be used with care,
394+ # because not all classes have default constructors.
395+ #
396+ NewObject : fn( cl_data : ClassData ) : JObject;
397+
398+ #
399+ # Duplicate the object. This function will create
400+ # a new instance of the object's class and perform
401+ # a shallow copy of the the objects data contents
402+ # into the new instance.
403+ # NOTE: the constructor of the new object is not invoked
404+ #
405+ DupObject : fn( obj : JObject ) : JObject;
406+
407+ #
408+ # Return a hash code based on the object's reference,
409+ # not its contents. This is called by
410+ # java.lang.Object.hashCode() as well as
411+ # System.identityHashCode().
412+ #
413+ IdentityHash : fn( obj : JObject ) : int;
414+
415+ #
416+ # Allocate a java string object and place the
417+ # dis string as its contents.
418+ #
419+ NewString : fn( val : string ) : JString;
420+
421+ #
422+ # Just like NewString but return as a
423+ # JObject type, rather then JString
424+ #
425+ NewStringObject : fn( val : string ) : JObject;
426+
427+ #
428+ # Set object/class data fields.
429+ # Must pass the "object instance"/"class data" along with the
430+ # field name and the value it should be set to. The contents of
431+ # the 'val' union type is used to determine the field type and if
432+ # they are not compatable the function fails.
433+ #
434+ # RETURN: JNI->OK=> success;
435+ # JNI->ERR=> failure
436+ #
437+ SetStaticField : fn( cl_data : ClassData, name : string, val : ref Value ) : int;
438+ SetObjField : fn( obj : JObject, name : string, val : ref Value ) : int;
439+
440+ # Get object/class data fields.
441+ # Must pass the "object instance"/"class data" along with the field
442+ # name and a "type signature" (see JVM reference). The type sig must
443+ # match the actual field sig exactly.
444+ #
445+ # RETURN: nil=> failure;
446+ # non-nil=> a 'Value' union type with the field contents
447+ #
448+ GetStaticField : fn( cl_data : ClassData, name : string, typ : string ) : ref Value;
449+ GetObjField : fn( obj : JObject, name : string, typ : string ) : ref Value;
450+
451+
452+ #
453+ # Call a method:
454+ # cl_data/obj : the class or object being called
455+ # meth : name of method to call
456+ # sig : signature of method being called
457+ # args : array of args to pass (nil==void) 'this' is implicitly
458+ # passed for dynamic (object) method calls
459+ # return : tuple: value of method call (nil==void), error code
460+ #
461+ # example:
462+ # v := Value.Int(99);
463+ # args := array[] of {v};
464+ # (val,err) := CallMeth( o, "foo", "(I)I", args );
465+ # if ( err == JNI->OK )
466+ # sys->print( "return: %d\n", val.Int() );
467+ #
468+ CallStatic : fn( cl_data : ClassData, meth : string, sig : string, args : array of ref Value ) : (ref Value,int);
469+ CallMethod : fn( obj : JObject, meth : string, sig : string, args : array of ref Value ) : (ref Value,int);
470+
471+
472+ #
473+ # Method call error codes
474+ #
475+ CALLERR_NOMETHOD, # method not found
476+ CALLERR_BADSIG, # bad signature
477+ CALLERR_BADARGCNT, # arg count mismatch
478+ CALLERR_BADARG # argument mismatch: errcode-CALLERR_BADARG==argument position
479+ # 'badarg' must be last.
480+ : con (iota+1);
481+
482+
483+ ##
484+ ## Object/Class comparison functions
485+ ##
486+
487+ IsInstanceOf : fn( obj : JObject, cl_data : ClassData ) : JBoolean;
488+ IsAssignable : fn( assignee, assignTo : JClass ) : JBoolean;
489+ IsSameObject : fn( obj1, obj2 : JObject ) : JBoolean;
490+
491+ # Check if 'ary' can be assigned to an instance with matching 'desc'.
492+ # If 'ary' or 'desc' are nil then return FALSE.
493+ ArrayInstanceOf : fn( ary : JArray, desc : ref Descriptor ) : JBoolean;
494+
495+ # Is the object an array? (nil==FALSE)
496+ IsArray : fn( obj : JObject ) : JBoolean;
497+
498+ ##
499+ ## Support for Serializable
500+ ##
501+
502+ # Return the modifiers for the item.
503+ # Return 0 if field or method not found in class.
504+ # Do not search for fields/methods in superclass.
505+ # string args are same format as strings returned
506+ # by GetFieldSignatures and GetMethodSignatures.
507+ #
508+ GetClassFlags : fn(jcl : JClass) : int;
509+ GetFieldFlags : fn(jcl : JClass, fieldsignature : string) : int;
510+ GetMethodFlags : fn(jcl : JClass, methodsignature : string) : int;
511+
512+ # Return array of Fields/Methods plus signatures as strings.
513+ # Should be limited Fields/methods in this class, not superclass.
514+ # Returned value strings are "fieldormethodname signature".
515+ #
516+ GetFieldSignatures : fn(jcl: JClass, excl : int) : JArrayJString;
517+ GetMethodSignatures : fn(jcl: JClass, excl : int) : JArrayJString;
518+
519+ ##
520+ ## Throwing Exceptions
521+ ##
522+
523+ #
524+ # Throw the pre-created 'throwable' object. The
525+ # 'throwable' object must be an instance of
526+ # "java.lang.Throwable", else failure.
527+ #
528+ Throw : fn( throwable : JObject );
529+ ThrowException : fn( name : string, msg : string );
530+
531+ #
532+ # return the current Java Exception. The object
533+ # returned can be used by "Throw" to re-throw it.
534+ #
535+ # ex is the current Inferno exception if in a rescue.
536+ # if ex is nil then the current value of culprit() is
537+ # returned (that may be nil). If ex is non nil and
538+ # culprit() is nil then ex is converted to the appropriate
539+ # Java throwable and returned.
540+ #
541+ JavaException: fn( ex : string ) : JObject;
542+
543+ #
544+ # Clear any current Exception for the calling thread.
545+ #
546+ ExceptionClear : fn();
547+
548+ ##
549+ ## Array functions
550+ ##
551+
552+ GetArrayLength : fn( ary : JArray ) : int;
553+
554+ #
555+ # functions to make "java" arrays from limbo arrays
556+ #
557+ MkAByte : fn( ary : array of byte ) : JArrayB;
558+ MkAChar : fn( ary : array of int ) : JArrayC;
559+ MkAShort : fn( ary : array of int ) : JArrayS;
560+ MkAInt : fn( ary : array of int ) : JArrayI;
561+ MkALong : fn( ary : array of big ) : JArrayJ;
562+ MkAFloat : fn( ary : array of real ) : JArrayF;
563+ MkADouble : fn( ary : array of real ) : JArrayD;
564+ MkABoolean : fn( ary : array of byte ) : JArrayZ;
565+ MkAObject : fn( ary : array of JObject ) : JArrayJObject;
566+ MkAString : fn( ary : array of string ) : JArrayJString;
567+
568+ MkAAByte : fn( aary : array of array of byte ) : JArray;
569+ MkAAInt : fn( aary : array of array of int ) : JArray;
570+
571+ # This can be used to create arrays of arbitrary dimensions.
572+ MkAJArray : fn( ary : array of JArray ) : JArray;
573+
574+ # make a JArrayC from a Dis string
575+ StringToAChar : fn( s : string ) : JArrayC;
576+
577+ ##
578+ ## Monitor, locking, and Thread functions
579+ ##
580+
581+ #
582+ # Lock or unlock the object's associated
583+ # lock. Block until the operation is complete.
584+ # Upon an error: FatalError() is called
585+ #
586+ MonitorEnter : fn( obj : JObject );
587+ MonitorExit : fn( obj :JObject );
588+
589+ #
590+ # Notify any waiters.
591+ # all==1 => notify all
592+ # *Lock* version will do a enter/exit.
593+ #
594+ MonitorLockNotify : fn( obj : JObject, all : int );
595+ MonitorNotify : fn( obj : JObject, all : int );
596+
597+ #
598+ # Attach a "Limbo thread" to the "Java vm".
599+ # This allows a Limbo "spawned" thread to
600+ # look like a "Java thread" to the Java Classes.
601+ #
602+ # return 0=>success; <0=>fail
603+ #
604+ AttachCurrentThread : fn( arg : ref ThreadAttachArgs ) : int;
605+
606+ #
607+ # Detach a thread from the "java VM".
608+ #
609+ DetachCurrentThread : fn() : int;
610+
611+ #
612+ # returns the Main thread group.
613+ #
614+ MainThreadGroup : fn() : JObject;
615+
616+ ##
617+ ## Utility Functions
618+ ##
619+
620+ # flags indicating which methods to find
621+ METH_PRIVATE, # private methods
622+ METH_VIRTUAL, # virtual methods
623+ METH_STATIC, # static methods
624+ METH_INIT # constructors
625+ : con ( 1 << iota );
626+
627+ #
628+ # look up a method based on its name and signature.
629+ #
630+ # class : class descritpor to look in
631+ # name : method name to look up
632+ # sig : method signature
633+ # flags : specifies what type of method to find and
634+ # can be any of the above flags or'ed togeather.
635+ #
636+ # return: the (module,index) of the method
637+ #
638+ FindMethod : fn( class : ClassData,
639+ name : string,
640+ sig : string,
641+ flags : int ) : (Nilmod,int);
642+
643+ #
644+ # If c represents a Java primitive type, return
645+ # T_BOOLEAN..T_LONG or T_VOID; otherwise, return 0.
646+ # Also return 0 if T_VOID applies, but ignorevoid != 0.
647+ #
648+ PrimitiveIndex: fn(c : JClass, ignorevoid : int) : int;
649+
650+ #
651+ # Convert a Java type signature string into
652+ # a type descriptor structure. The signature
653+ # passed in can represent any single type (including
654+ # a method). Extra characters on the end are ignored.
655+ #
656+ JSigToDescriptor : fn( sig : string ) : ref Descriptor;
657+
658+ #
659+ # Throw a java.lang.InternalError
660+ #
661+ FatalError : fn( msg : string );
662+
663+ #
664+ # Indicate to loader a native module init()
665+ # function has failed.
666+ #
667+ InitError : fn( msg : string );
668+
669+ #
670+ # Return an instance of the Cast module.
671+ #
672+ CastMod : fn() : Cast;
673+
674+ #
675+ # Return an instance of the Low module.
676+ #
677+ LowMod : fn() : Low;
678+
679+ # return the current draw context
680+ getContext:fn(): ref Draw->Context;
681+
682+ #
683+ # The following routines are called by the JavaClassLoader
684+ # module to initialize JNI. Native method modules must not
685+ # call thease routines.
686+ #
687+ jinit : fn( jldr : JavaClassLoader, jass : JavaAssist );
688+ Self: fn(s: Sys, j: JNI): (Nilmod, string);
689+ init: fn(j: JNI);
690+};