History

Preliminary exception support implementation

Dmitry Kabak (userdima committed 13 years ago

Commit 0ccfe031 parent 3968fd78 files · +73 −8Browse files

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

Unified · Split

8 files
  1. java/appl/j2d/asm.b +11 −0
  2. java/appl/j2d/dis.b +30 −1
  3. java/appl/j2d/java.m +1 −0
  4. java/appl/j2d/loader.b +1 −1
  5. java/appl/j2d/main.b +1 −0
  6. java/appl/j2d/mdata.b +1 −1
  7. java/appl/j2d/util.b +3 −1
  8. java/appl/j2d/xlate.b +25 −4
java/appl/j2d/asm.b+11−0
@@ -216,6 +216,17 @@ instconv(in: ref Inst): string · 215 unmodified lines
216 return s;216 return s;
217}217}
218 218
219asmhandlers()
220{
221 nex := len class.handlers;
222 bout.puts("\texceptions " + string nex + "\n");
223 for (i := 0; i < len class.handlers; i++) {
224 h := class.handlers[i];
225 bout.puts(sprint("\texception\t%d, %d, 0, -1, 0, 0\n", h.start_pc, h.end_pc));
226 bout.puts(sprint("\texctab\t*, %d\n", h.handler_pc));
227 }
228}
229
219ehtable(c: ref Code)230ehtable(c: ref Code)
220{231{
221 i: int;232 i: int;
java/appl/j2d/dis.b+30−1
@@ -266,10 +266,38 @@ disinst() · 265 unmodified lines
266 ibuf = nil;266 ibuf = nil;
267}267}
268 268
269disstr(s: string)
270{
271 a := array of byte s;
272 for (i := 0; i < len a; i++)
273 bout.putb(a[i]);
274 discon(0);
275}
276
277dishandlers()
278{
279 discon(len class.handlers);
280 for (i := 0; i < len class.handlers; i++) {
281 h := class.handlers[i];
282 # FIXME: exception object offset
283 discon(42);
284 discon(h.start_pc);
285 discon(h.end_pc);
286 discon(-1); # type to destroy, nil
287 discon(1); # number of exception handlers
288 disstr("*");
289 discon(h.handler_pc);
290 discon(0);
291 }
292 # Don't know what is it, but zero-byte is
293 # expected after handler section
294 discon(0);
295}
296
269disout()297disout()
270{298{
271 discon(XMAGIC);299 discon(XMAGIC);
272 discon(DONTCOMPILE); # runtime "hints"300 discon(DONTCOMPILE | HASEXCEPT); # dis flags
273 disstackext(); # minimum stack extent size301 disstackext(); # minimum stack extent size
274 disninst();302 disninst();
275 disnvar();303 disnvar();
@@ -281,4 +309,5 @@ disout() · 5 unmodified lines
281 disvar();309 disvar();
282 dismod();310 dismod();
283 dislinks();311 dislinks();
312 dishandlers();
284}313}
java/appl/j2d/java.m+1−0
@@ -202,6 +202,7 @@ Class: adt { # ClassFile · 201 unmodified lines
202 methods_count: int;202 methods_count: int;
203 methods: array of ref Method;203 methods: array of ref Method;
204 source_file: int;204 source_file: int;
205 handlers: array of ref Handler;
205};206};
206 207
207Addr: adt { # Dis operand208Addr: adt { # Dis operand
java/appl/j2d/loader.b+1−1
@@ -308,7 +308,7 @@ byte2Class(text: array of byte) · 307 unmodified lines
308 mp: ref Method;308 mp: ref Method;
309 309
310 uSet(text);310 uSet(text);
311 class = ref Class(0, 0, 0, nil, nil, 0, 0, 0, 0, nil, 0, nil, 0, nil, 0);311 class = ref Class(0, 0, 0, nil, nil, 0, 0, 0, 0, nil, 0, nil, 0, nil, 0, nil);
312 312
313 if(u4() != int 16rCAFEBABE)313 if(u4() != int 16rCAFEBABE)
314 verifyerrormess("magic");314 verifyerrormess("magic");
java/appl/j2d/main.b+1−0
@@ -51,6 +51,7 @@ translate(in: string, out: string) · 50 unmodified lines
51 asmvar();51 asmvar();
52 asmmod();52 asmmod();
53 asmlinks();53 asmlinks();
54 asmhandlers();
54 } else55 } else
55 disout(); # generate .dis file56 disout(); # generate .dis file
56 57
java/appl/j2d/mdata.b+1−1
@@ -47,7 +47,7 @@ Hentry: adt { · 46 unmodified lines
47};47};
48 48
49htable := array [Hashsize] of ref Hentry;49htable := array [Hashsize] of ref Hentry;
50mpoff: int;50mpoff := IBY2WD; # skip first cell, as it's reserved for nil ptr
51 51
52mplist: ref Datum;52mplist: ref Datum;
53mptail: ref Datum;53mptail: ref Datum;
java/appl/j2d/util.b+3−1
@@ -405,7 +405,9 @@ reset() · 404 unmodified lines
405 # mdata.b405 # mdata.b
406 for(i = 0; i < Hashsize; i++)406 for(i = 0; i < Hashsize; i++)
407 htable[i] = nil;407 htable[i] = nil;
408 mpoff = 0;408 # mpoff should not be zero,
409 # as zero is reserved for nil ptr
410 mpoff = IBY2WD;
409 mplist = nil;411 mplist = nil;
410 mptail = nil;412 mptail = nil;
411 llist = nil;413 llist = nil;
java/appl/j2d/xlate.b+25−4
@@ -1382,7 +1382,7 @@ xjavastore(op: int) · 1381 unmodified lines
1382 i: ref Inst;1382 i: ref Inst;
1383 1383
1384 if(op == IMOVP && J.bb.js == J && int (J.bb.flags & BB_FINALLY))1384 if(op == IMOVP && J.bb.js == J && int (J.bb.flags & BB_FINALLY))
1385 ; # astore instruction at the start of a finally block1385 print("[The voice of Translator] removed some MOV at %d\n", op); # astore instruction at the start of a finally block
1386 else if(J.dst.mode != Anone) { # marked for explicit mov1386 else if(J.dst.mode != Anone) { # marked for explicit mov
1387 i = newi(op);1387 i = newi(op);
1388 *i.s = *code.j[J.src[0]].dst;1388 *i.s = *code.j[J.src[0]].dst;
@@ -2072,6 +2072,20 @@ ehinst: ref EHInst; · 683 unmodified lines
2072trylist: ref Try;2072trylist: ref Try;
2073distrylist: ref Try;2073distrylist: ref Try;
2074 2074
2075#
2076# Dis pc by jinst index
2077#
2078
2079instpc(jix: int): int
2080{
2081 j := code.j[jix];
2082 while(j.dis == nil) {
2083 jix += j.size;
2084 j = code.j[jix];
2085 }
2086 return j.dis.pc;
2087}
2088
2075#2089#
2076# Save an EH branch instruction for later patching.2090# Save an EH branch instruction for later patching.
2077#2091#
@@ -2814,9 +2828,16 @@ java2dis() · 736 unmodified lines
2814 jix += J.size;2828 jix += J.size;
2815 }2829 }
2816 # handle exception handlers2830 # handle exception handlers
2817 for(t := trylist; t != nil; t = t.next) {2831 hbase := len class.handlers;
2818 # just convert pc's and append the entries to global distrylist2832 newhandlers := array [len class.handlers + code.nex] of ref Handler;
2819 2833 newhandlers[:] = class.handlers[:];
2834 class.handlers = newhandlers;
2835 for(i := 0; i < code.nex; i++) {
2836 h := code.ex[i];
2837 # by this time all the needed code is already translated, so we can
2838 # just convert pc's and append the entries to global handlers section
2839 class.handlers[hbase++] = ref Handler(instpc(h.start_pc), instpc(h.end_pc),
2840 instpc(h.handler_pc), 0);
2820 }2841 }
2821 J = nil;2842 J = nil;
2822}2843}