| @@ -1556,24 +1556,24 @@ iinc(val: int, ix: int) · 1555 unmodified lines |
| 1556 | 1556 | # J.u.i is destination PC (relative from J.pc) |
| 1557 | 1557 | # |
| 1558 | 1558 | |
| 1559 | | −tldiff(): int |
| 1560 | | −{ |
| 1561 | | − tls, tld: int; |
| 1562 | | − ix: int; |
| 1563 | | − |
| 1564 | | − pick jp := J { |
| 1565 | | − Pi => |
| 1566 | | − ix = jp.i; |
| 1567 | | − * => |
| 1568 | | − badpick("tldiff"); |
| 1569 | | − } |
| 1570 | | − |
| 1571 | | − tld = 0; |
| 1572 | | − tls = trylevel(J.pc); |
| 1573 | | − if(tls > 0) |
| 1574 | | − tld = trylevel(J.pc+ix); |
| 1575 | | − return tls-tld; |
| 1576 | | −} |
| 1559 | +#tldiff(): int |
| 1560 | +#{ |
| 1561 | +# tls, tld: int; |
| 1562 | +# ix: int; |
| 1563 | +# |
| 1564 | +# pick jp := J { |
| 1565 | +# Pi => |
| 1566 | +# ix = jp.i; |
| 1567 | +# * => |
| 1568 | +# badpick("tldiff"); |
| 1569 | +# } |
| 1570 | +# |
| 1571 | +# tld = 0; |
| 1572 | +# tls = trylevel(J.pc); |
| 1573 | +# if(tls > 0) |
| 1574 | +# tld = trylevel(J.pc+ix); |
| 1575 | +# return tls-tld; |
| 1576 | +#} |
| 1577 | 1577 | |
| 1578 | 1578 | # |
| 1579 | 1579 | # Java if_acmp<cond>, if_icmp<cond>, if<cond>, ifnonnull, ifnull. |
| @@ -2105,21 +2105,8 @@ saveehinst(i: ref Inst) · 525 unmodified lines |
| 2105 | 2105 | |
| 2106 | 2106 | patchehinst() |
| 2107 | 2107 | { |
| 2108 | | − ehi: ref EHInst; |
| 2109 | | − i: ref Inst; |
| 2110 | | − j: ref Jinst; |
| 2111 | | − jix: int; |
| 2112 | | − |
| 2113 | | − for(ehi = ehinst; ehi != nil; ehi = ehi.next) { |
| 2114 | | − i = ehi.i; |
| 2115 | | − jix = i.d.ival; |
| 2116 | | − j = code.j[jix]; |
| 2117 | | − while(j.dis == nil) { |
| 2118 | | − jix += j.size; |
| 2119 | | − j = code.j[jix]; |
| 2120 | | − } |
| 2121 | | − i.d.ival = j.dis.pc; |
| 2122 | | − } |
| 2108 | + for(ehi := ehinst; ehi != nil; ehi = ehi.next) |
| 2109 | + ehi.i.d.ival = instpc(ehi.i.d.ival); |
| 2123 | 2110 | ehinst = nil; |
| 2124 | 2111 | } |
| 2125 | 2112 | |
| @@ -2172,97 +2159,24 @@ trylevel(pc: int): int · 46 unmodified lines |
| 2172 | 2159 | return level; |
| 2173 | 2160 | } |
| 2174 | 2161 | |
| 2175 | | −# |
| 2176 | | −# Install an exception handler: call sys.rescue("*", nil). |
| 2177 | | −# |
| 2178 | | − |
| 2179 | | −rescue(): ref Addr |
| 2180 | | −{ |
| 2181 | | − print("rescue()\n"); |
| 2182 | | − #imframe, i: ref Inst; |
| 2183 | | − #cr: ref Creloc; |
| 2184 | | − #frm, frf: ref Freloc; |
| 2185 | | −# |
| 2186 | | − #cr = getCreloc(RLOADER); |
| 2187 | | − #frm = getFreloc(cr, RSYS, nil, 0); |
| 2188 | | − #frf = getFreloc(cr, "rescue", nil, 0); |
| 2189 | | −# |
| 2190 | | − #imframe = loadermframe(frm, frf); |
| 2191 | | −# |
| 2192 | | − #i = newi(IMOVP); |
| 2193 | | − #addrsind(i.s, Amp, mpstring("*")); |
| 2194 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGSIZE); |
| 2195 | | − #addDreloc(i, PSRC, PSIND); |
| 2196 | | −# |
| 2197 | | − #i = newi(IMOVP); |
| 2198 | | − #addrsind(i.s, Afp, REFSYSEX); |
| 2199 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGSIZE+IBY2WD); |
| 2200 | | −# |
| 2201 | | − #i = newi(ILEA); |
| 2202 | | − #addrsind(i.s, Afp, getreg(DIS_W)); |
| 2203 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGRET*IBY2WD); |
| 2204 | | −# |
| 2205 | | − #loadermcall(imframe, frf, frm); |
| 2206 | | − #relreg(imframe.d); |
| 2207 | | −# |
| 2208 | | − #return i.s; |
| 2209 | | − return nil; |
| 2210 | | −} |
| 2211 | | − |
| 2212 | | −# |
| 2213 | | −# Uninstall one or more exception handlers: call sys.unrescue() n times. |
| 2214 | | −# |
| 2215 | | − |
| 2216 | | −unrescue(n: int) |
| 2217 | | −{ |
| 2218 | | − print("unrescue()\n"); |
| 2219 | | − #imframe: ref Inst; |
| 2220 | | − #cr: ref Creloc; |
| 2221 | | − #frm, frf: ref Freloc; |
| 2222 | | −# |
| 2223 | | − #cr = getCreloc(RLOADER); |
| 2224 | | − #frm = getFreloc(cr, RSYS, nil, 0); |
| 2225 | | − #frf = getFreloc(cr, "unrescue", nil, 0); |
| 2226 | | −# |
| 2227 | | − #while(n > 0) { |
| 2228 | | − # imframe = loadermframe(frm, frf); |
| 2229 | | − # loadermcall(imframe, frf, frm); |
| 2230 | | − # relreg(imframe.d); |
| 2231 | | − # n--; |
| 2232 | | − #} |
| 2233 | | −} |
| 2234 | | − |
| 2235 | 2162 | # |
| 2236 | 2163 | # Current handler doesn't catch current exception. |
| 2237 | | −# Call sys.raise(@jex) to propagate (rethrow) the exception. |
| 2164 | +# Call raise to propagate (rethrow) the exception. |
| 2238 | 2165 | # |
| 2239 | 2166 | |
| 2240 | 2167 | rethrow(): ref Inst |
| 2241 | 2168 | { |
| 2242 | 2169 | print("rethrow()\n"); |
| 2243 | | − #imframe, i: ref Inst; |
| 2244 | | − #cr: ref Creloc; |
| 2245 | | − #frm, frf: ref Freloc; |
| 2246 | | −# |
| 2247 | | − #cr = getCreloc(RLOADER); |
| 2248 | | − #frm = getFreloc(cr, RSYS, nil, 0); |
| 2249 | | − #frf = getFreloc(cr, "raise", nil, 0); |
| 2250 | | −# |
| 2170 | + i: ref Inst; |
| 2171 | + |
| 2172 | + # FIXME: is that needed? |
| 2251 | 2173 | #if(M.access_flags & ACC_SYNCHRONIZED && trylevel(J.pc) == 1) |
| 2252 | 2174 | # mon_or_throw(Jmonitorexit, M.access_flags, 0); |
| 2253 | | −# |
| 2254 | | − #imframe = loadermframe(frm, frf); |
| 2255 | | −# |
| 2256 | | − #i = newi(IMOVP); |
| 2257 | | − #addrsind(i.s, Amp, 0); |
| 2258 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGSIZE); |
| 2259 | | − #LTIpatch(getFreloc(cr, RJEX, nil, 0), i, PSRC, PSIND); |
| 2260 | | −# |
| 2261 | | − #i = loadermcall(imframe, frf, frm); |
| 2262 | | − #relreg(imframe.d); |
| 2263 | | −# |
| 2264 | | − #return i; |
| 2265 | | − return nil; |
| 2175 | + |
| 2176 | + i = newi(IRAISE); |
| 2177 | + addrsind(i.s, Afp, EXSTR); |
| 2178 | + |
| 2179 | + return i; |
| 2266 | 2180 | } |
| 2267 | 2181 | |
| 2268 | 2182 | # |
| @@ -2272,26 +2186,26 @@ rethrow(): ref Inst · 3 unmodified lines |
| 2272 | 2186 | catch() |
| 2273 | 2187 | { |
| 2274 | 2188 | print("catch()\n"); |
| 2275 | | − #imframe, i: ref Inst; |
| 2276 | | − #cr: ref Creloc; |
| 2277 | | − #frm, frf: ref Freloc; |
| 2278 | | −# |
| 2279 | | − #cr = getCreloc(RLOADER); |
| 2280 | | − #frm = getFreloc(cr, RMP, nil, 0); |
| 2281 | | − #frf = getFreloc(cr, "culprit", nil, 0); |
| 2282 | | −# |
| 2283 | | − #imframe = loadermframe(frm, frf); |
| 2284 | | −# |
| 2285 | | − #i = newi(IMOVP); |
| 2286 | | − #addrsind(i.s, Afp, REFSYSEX); |
| 2287 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGSIZE); |
| 2288 | | −# |
| 2289 | | − #i = newi(ILEA); |
| 2290 | | − #addrsind(i.s, Afp, EXOBJ); # put in known location |
| 2291 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGRET*IBY2WD); |
| 2292 | | −# |
| 2293 | | − #loadermcall(imframe, frf, frm); |
| 2294 | | − #relreg(imframe.d); |
| 2189 | + imframe, i: ref Inst; |
| 2190 | + cr: ref Creloc; |
| 2191 | + frm, frf: ref Freloc; |
| 2192 | + |
| 2193 | + cr = getCreloc(RLOADER); |
| 2194 | + frm = getFreloc(cr, RMP, nil, 0); |
| 2195 | + frf = getFreloc(cr, "culprit", nil, 0); |
| 2196 | + |
| 2197 | + imframe = loadermframe(frm, frf); |
| 2198 | + |
| 2199 | + i = newi(IMOVP); |
| 2200 | + addrsind(i.s, Afp, EXSTR); |
| 2201 | + addrdind(i.d, Afpind, imframe.d.offset, REGSIZE); |
| 2202 | + |
| 2203 | + i = newi(ILEA); |
| 2204 | + addrsind(i.s, Afp, EXOBJ); # put in known location |
| 2205 | + addrdind(i.d, Afpind, imframe.d.offset, REGRET*IBY2WD); |
| 2206 | + |
| 2207 | + loadermcall(imframe, frf, frm); |
| 2208 | + relreg(imframe.d); |
| 2295 | 2209 | } |
| 2296 | 2210 | |
| 2297 | 2211 | # |
| @@ -2301,38 +2215,37 @@ catch() · 3 unmodified lines |
| 2301 | 2215 | chkhandler(exname: string): ref Addr |
| 2302 | 2216 | { |
| 2303 | 2217 | print("chkhandler()\n"); |
| 2304 | | − #imframe, i: ref Inst; |
| 2305 | | − #rtc: ref RTClass; |
| 2306 | | − #cr: ref Creloc; |
| 2307 | | − #frm, frf: ref Freloc; |
| 2308 | | −# |
| 2309 | | − #rtc = getRTClass(exname); |
| 2310 | | − #callrtload(rtc, exname); |
| 2311 | | −# |
| 2312 | | − #cr = getCreloc(RLOADER); |
| 2313 | | − #frm = getFreloc(cr, RMP, nil, 0); |
| 2314 | | − #frf = getFreloc(cr, "instanceof", nil, 0); |
| 2315 | | −# |
| 2316 | | − #imframe = loadermframe(frm, frf); |
| 2317 | | −# |
| 2318 | | − #i = newi(IMOVP); |
| 2319 | | − #addrsind(i.s, Afp, EXOBJ); |
| 2320 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGSIZE); |
| 2321 | | −# |
| 2322 | | − #i = newi(IMOVP); |
| 2323 | | − #addrsind(i.s, Amp, 0); |
| 2324 | | − #RTIpatch(getRTReloc(rtc, RADT, nil, 0), i, PSRC, PSIND); |
| 2325 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGSIZE+IBY2WD); |
| 2326 | | −# |
| 2327 | | − #i = newi(ILEA); |
| 2328 | | − #addrsind(i.s, Afp, getreg(DIS_W)); |
| 2329 | | − #addrdind(i.d, Afpind, imframe.d.offset, REGRET*IBY2WD); |
| 2330 | | −# |
| 2331 | | − #loadermcall(imframe, frf, frm); |
| 2332 | | − #relreg(imframe.d); |
| 2333 | | −# |
| 2334 | | − #return i.s; |
| 2335 | | − return nil; |
| 2218 | + imframe, i: ref Inst; |
| 2219 | + rtc: ref RTClass; |
| 2220 | + cr: ref Creloc; |
| 2221 | + frm, frf: ref Freloc; |
| 2222 | + |
| 2223 | + rtc = getRTClass(exname); |
| 2224 | + callrtload(rtc, exname); |
| 2225 | + |
| 2226 | + cr = getCreloc(RLOADER); |
| 2227 | + frm = getFreloc(cr, RMP, nil, 0); |
| 2228 | + frf = getFreloc(cr, "instanceof", nil, 0); |
| 2229 | + |
| 2230 | + imframe = loadermframe(frm, frf); |
| 2231 | + |
| 2232 | + i = newi(IMOVP); |
| 2233 | + addrsind(i.s, Afp, EXOBJ); |
| 2234 | + addrdind(i.d, Afpind, imframe.d.offset, REGSIZE); |
| 2235 | + |
| 2236 | + i = newi(IMOVP); |
| 2237 | + addrsind(i.s, Amp, 0); |
| 2238 | + RTIpatch(getRTReloc(rtc, RADT, nil, 0), i, PSRC, PSIND); |
| 2239 | + addrdind(i.d, Afpind, imframe.d.offset, REGSIZE+IBY2WD); |
| 2240 | + |
| 2241 | + i = newi(ILEA); |
| 2242 | + addrsind(i.s, Afp, getreg(DIS_W)); |
| 2243 | + addrdind(i.d, Afpind, imframe.d.offset, REGRET*IBY2WD); |
| 2244 | + |
| 2245 | + loadermcall(imframe, frf, frm); |
| 2246 | + relreg(imframe.d); |
| 2247 | + |
| 2248 | + return i.s; |
| 2336 | 2249 | } |
| 2337 | 2250 | |
| 2338 | 2251 | # |
| @@ -2342,21 +2255,13 @@ chkhandler(exname: string): ref Addr · 3 unmodified lines |
| 2342 | 2255 | trystart(t: ref Try) |
| 2343 | 2256 | { |
| 2344 | 2257 | print("trystart()\n"); |
| 2345 | | − ibeqw, i: ref Inst; |
| 2258 | + ijmp, i: ref Inst; |
| 2346 | 2259 | a: ref Addr; |
| 2347 | 2260 | c: ref Catch; |
| 2348 | 2261 | |
| 2349 | | − a = rescue(); |
| 2350 | | − |
| 2351 | | − #ibeqw = newi(IBEQW); |
| 2352 | | − #*ibeqw.s = *a; |
| 2353 | | − #relreg(a); |
| 2354 | | − #addrimm(ibeqw.m, 0); # Sys.HANDLER == 0 |
| 2355 | | − #addrimm(ibeqw.d, 0); |
| 2356 | | − |
| 2357 | | − # code executed when sys.rescue() "returns" Sys.EXCEPTION |
| 2358 | | − |
| 2359 | | − unrescue(1); |
| 2262 | + # always skip this block in normal flow |
| 2263 | + ijmp = newi(IJMP); |
| 2264 | + addrimm(ijmp.d, 0); |
| 2360 | 2265 | |
| 2361 | 2266 | catch(); |
| 2362 | 2267 | |
| @@ -2374,14 +2279,16 @@ trystart(t: ref Try) · 11 unmodified lines |
| 2374 | 2279 | i = newi(IJMP); |
| 2375 | 2280 | addrimm(i.d, t.any_pc); |
| 2376 | 2281 | saveehinst(i); |
| 2377 | | − } #else |
| 2378 | | − # i = rethrow(); |
| 2282 | + } else |
| 2283 | + i = rethrow(); |
| 2379 | 2284 | |
| 2380 | | − #ibeqw.d.ival = i.pc+1; |
| 2285 | + ijmp.d.ival = i.pc + 1; |
| 2286 | + t.any_pc = ijmp.pc + 1; |
| 2287 | + print("Generated handler block at %d - %d\n", ijmp.pc, i.pc); |
| 2381 | 2288 | |
| 2382 | 2289 | # |
| 2383 | | − # rtload()'s done in Sys.EXCEPTION branch are not valid |
| 2384 | | − # for normal flow (Sys.HANDLER branch) |
| 2290 | + # rtload()'s done in handler branch are not valid |
| 2291 | + # for normal flow, as they are not executed |
| 2385 | 2292 | # |
| 2386 | 2293 | rtncache = 0; |
| 2387 | 2294 | } |
| @@ -2392,17 +2299,12 @@ trystart(t: ref Try) · 4 unmodified lines |
| 2392 | 2299 | |
| 2393 | 2300 | tryhandling() |
| 2394 | 2301 | { |
| 2395 | | − #print("tryhandling()\n"); |
| 2396 | | − #t: ref Try; |
| 2397 | | −# |
| 2398 | | − #for(t = trylist; t != nil; t = t.next) { |
| 2399 | | − # # > 1 try block can have the same start_pc |
| 2400 | | − # if(t.start_pc == J.pc) |
| 2401 | | − # trystart(t); |
| 2402 | | − # # try block may consist of just 1 bytecode |
| 2403 | | − # if(t.end_pc == J.pc+J.size) |
| 2404 | | − # callunrescue = 1; |
| 2405 | | − #} |
| 2302 | + for(t := trylist; t != nil; t = t.next) { |
| 2303 | + # FIXME |
| 2304 | + # > 1 try block can have the same start_pc |
| 2305 | + if(t.start_pc == J.pc) |
| 2306 | + trystart(t); |
| 2307 | + } |
| 2406 | 2308 | } |
| 2407 | 2309 | |
| 2408 | 2310 | # |
| @@ -2436,7 +2338,7 @@ java2dis() · 27 unmodified lines |
| 2436 | 2338 | if(J.pc == 0 && M.access_flags & ACC_SYNCHRONIZED) |
| 2437 | 2339 | mon_or_throw(Jmonitorenter, M.access_flags, 0); |
| 2438 | 2340 | |
| 2439 | | − #tryhandling(); |
| 2341 | + tryhandling(); |
| 2440 | 2342 | |
| 2441 | 2343 | if(jix+J.size < code.code_length) |
| 2442 | 2344 | jnext = code.j[jix+J.size]; |
| @@ -2828,16 +2730,12 @@ java2dis() · 385 unmodified lines |
| 2828 | 2730 | jix += J.size; |
| 2829 | 2731 | } |
| 2830 | 2732 | # handle exception handlers |
| 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]; |
| 2733 | + for(t := trylist; t != nil; t = t.next) { |
| 2837 | 2734 | # 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); |
| 2735 | + # just convert pc's and prepend the entries to global handlers section |
| 2736 | + # the final list will be reverted, and that is what we need |
| 2737 | + class.handlers = ref Handler(instpc(t.start_pc), instpc(t.end_pc), |
| 2738 | + t.any_pc, 0) :: class.handlers; |
| 2841 | 2739 | } |
| 2842 | 2740 | J = nil; |
| 2843 | 2741 | } |