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
216216 return s;
217217 }
218218
219+asmhandlers()
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+
219230 ehtable(c: ref Code)
220231 {
221232 i: int;
java/appl/j2d/dis.b+30−1
@@ -266,10 +266,38 @@ disinst() · 265 unmodified lines
266266 ibuf = nil;
267267 }
268268
269+disstr(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+
277+dishandlers()
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+
269297 disout()
270298 {
271299 discon(XMAGIC);
272− discon(DONTCOMPILE); # runtime "hints"
300+ discon(DONTCOMPILE | HASEXCEPT); # dis flags
273301 disstackext(); # minimum stack extent size
274302 disninst();
275303 disnvar();
@@ -281,4 +309,5 @@ disout() · 5 unmodified lines
281309 disvar();
282310 dismod();
283311 dislinks();
312+ dishandlers();
284313 }
java/appl/j2d/java.m+1−0
@@ -202,6 +202,7 @@ Class: adt { # ClassFile · 201 unmodified lines
202202 methods_count: int;
203203 methods: array of ref Method;
204204 source_file: int;
205+ handlers: array of ref Handler;
205206 };
206207
207208 Addr: adt { # Dis operand
java/appl/j2d/loader.b+1−1
@@ -308,7 +308,7 @@ byte2Class(text: array of byte) · 307 unmodified lines
308308 mp: ref Method;
309309
310310 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);
312312
313313 if(u4() != int 16rCAFEBABE)
314314 verifyerrormess("magic");
java/appl/j2d/main.b+1−0
@@ -51,6 +51,7 @@ translate(in: string, out: string) · 50 unmodified lines
5151 asmvar();
5252 asmmod();
5353 asmlinks();
54+ asmhandlers();
5455 } else
5556 disout(); # generate .dis file
5657
java/appl/j2d/mdata.b+1−1
@@ -47,7 +47,7 @@ Hentry: adt { · 46 unmodified lines
4747 };
4848
4949 htable := array [Hashsize] of ref Hentry;
50−mpoff: int;
50+mpoff := IBY2WD; # skip first cell, as it's reserved for nil ptr
5151
5252 mplist: ref Datum;
5353 mptail: ref Datum;
java/appl/j2d/util.b+3−1
@@ -405,7 +405,9 @@ reset() · 404 unmodified lines
405405 # mdata.b
406406 for(i = 0; i < Hashsize; i++)
407407 htable[i] = nil;
408− mpoff = 0;
408+ # mpoff should not be zero,
409+ # as zero is reserved for nil ptr
410+ mpoff = IBY2WD;
409411 mplist = nil;
410412 mptail = nil;
411413 llist = nil;
java/appl/j2d/xlate.b+25−4
@@ -1382,7 +1382,7 @@ xjavastore(op: int) · 1381 unmodified lines
13821382 i: ref Inst;
13831383
13841384 if(op == IMOVP && J.bb.js == J && int (J.bb.flags & BB_FINALLY))
1385− ; # astore instruction at the start of a finally block
1385+ print("[The voice of Translator] removed some MOV at %d\n", op); # astore instruction at the start of a finally block
13861386 else if(J.dst.mode != Anone) { # marked for explicit mov
13871387 i = newi(op);
13881388 *i.s = *code.j[J.src[0]].dst;
@@ -2072,6 +2072,20 @@ ehinst: ref EHInst; · 683 unmodified lines
20722072 trylist: ref Try;
20732073 distrylist: ref Try;
20742074
2075+#
2076+# Dis pc by jinst index
2077+#
2078+
2079+instpc(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+
20752089 #
20762090 # Save an EH branch instruction for later patching.
20772091 #
@@ -2814,9 +2828,16 @@ java2dis() · 736 unmodified lines
28142828 jix += J.size;
28152829 }
28162830 # handle exception handlers
2817− for(t := trylist; t != nil; t = t.next) {
2818− # just convert pc's and append the entries to global distrylist
2819−
2831+ hbase := len class.handlers;
2832+ newhandlers := array [len class.handlers + code.nex] of ref Handler;
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);
28202841 }
28212842 J = nil;
28222843 }