Changeset 1391 for branches/GNU/src/gcc/libjava/verify.cc
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/verify.cc (modified) (38 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/verify.cc
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 1 // defineclass.cc - defining a class from .class format. 2 2 3 /* Copyright (C) 2001, 2002 Free Software Foundation3 /* Copyright (C) 2001, 2002 Free Software Foundation 4 4 5 5 This file is part of libgcj. … … 127 127 128 128 return r; 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 129 157 } 130 158 … … 406 434 using namespace java::lang; 407 435 java::lang::ClassLoader *loader 408 = verifier->current_class->getClassLoader ();436 = verifier->current_class->getClassLoader(); 409 437 // We might see either kind of name. Sigh. 410 438 if (data.name->data[0] == 'L' … … 459 487 return key == k.key; 460 488 461 // The `null' type is convertible to any reference type.462 // FIXME: is this correct for THIS?489 // The `null' type is convertible to any 490 // 463 491 if (key == null_type || k.key == null_type) 464 492 return true; … … 572 600 if (key == reference_type) 573 601 return type (_Jv_GetArrayClass (data.klass, 574 data.klass->getClassLoader ()));602 data.klass->getClassLoader())); 575 603 else 576 604 verifier->verify_fail ("internal error in type::to_array()"); … … 696 724 { 697 725 java::lang::ClassLoader *loader 698 = verifier->current_class->getClassLoader ();726 = verifier->current_class->getClassLoader(); 699 727 k = _Jv_GetArrayClass (k, loader); 700 728 --arraycount; … … 794 822 // without really initializing. 795 823 type this_type; 824 825 826 827 828 829 796 830 797 831 // INVALID marks a state which is not on the linked list of states … … 812 846 locals = NULL; 813 847 local_changed = NULL; 848 814 849 } 815 850 … … 824 859 locals = new type[max_locals]; 825 860 local_changed = (bool *) _Jv_Malloc (sizeof (bool) * max_locals); 861 826 862 for (int i = 0; i < max_locals; ++i) 827 863 { … … 839 875 locals = new type[max_locals]; 840 876 local_changed = (bool *) _Jv_Malloc (sizeof (bool) * max_locals); 877 841 878 copy (orig, max_stack, max_locals, ret_semantics); 842 879 next = INVALID; … … 851 888 if (local_changed) 852 889 _Jv_Free (local_changed); 890 853 891 } 854 892 … … 871 909 { 872 910 _Jv_Free (mem); 911 912 913 914 915 916 917 918 919 920 921 873 922 } 874 923 … … 892 941 local_changed[i] = copy->local_changed[i]; 893 942 } 943 944 945 946 947 948 949 950 951 952 894 953 this_type = copy->this_type; 895 954 // Don't modify `next'. … … 916 975 for (int i = 0; i < max_locals; ++i) 917 976 local_changed[i] = false; 977 978 979 980 981 982 983 984 985 918 986 } 919 987 … … 945 1013 else 946 1014 { 947 // If the subroutines differ, indicate that the state 948 // changed. This is needed to detect when subroutines have 949 // merged. 950 changed = true; 1015 // If the subroutines differ, and we haven't seen this 1016 // subroutine before, indicate that the state changed. This 1017 // is needed to detect when subroutines have merged. 1018 bool found = false; 1019 for (subr_info *info = seen_subrs; info != NULL; info = info->next) 1020 { 1021 if (info->pc == state_old->subroutine) 1022 { 1023 found = true; 1024 break; 1025 } 1026 } 1027 if (! found) 1028 { 1029 add_subr (state_old->subroutine); 1030 changed = true; 1031 } 951 1032 } 952 1033 … … 1122 1203 } 1123 1204 1124 type pop64 ()1125 {1126 type r = pop_raw ();1127 if (! r.iswide ())1128 verify_fail ("wide pop of narrow type");1129 return r;1130 }1131 1132 1205 type pop_type (type match) 1133 1206 { … … 1135 1208 type t = pop_raw (); 1136 1209 if (! match.compatible (t, this)) 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1137 1223 verify_fail ("incompatible type on stack"); 1138 1224 return t; … … 1339 1425 int *prev_loc = &next_verify_pc; 1340 1426 int npc = next_verify_pc; 1341 bool skipped = false;1342 1427 1343 1428 while (npc != state::NO_NEXT) … … 1356 1441 } 1357 1442 1358 skipped = true;1359 1443 prev_loc = &states[npc]->next; 1360 1444 npc = states[npc]->next; … … 1435 1519 for (subr_info *subr = jsr_ptrs[csub]; subr != NULL; subr = subr->next) 1436 1520 { 1521 1522 1523 1524 1525 1526 1437 1527 // Temporarily modify the current state so it looks like we're 1438 1528 // in the enclosing context. … … 1484 1574 // might change the stack depth, so we can't make any assumptions 1485 1575 // about it. So we have yet another special case. We know that 1486 // at this point PC points to the instruction after the jsr. 1487 1488 // FIXME: what if we have a jsr at the end of the code, but that 1489 // jsr has no corresponding ret? Is this verifiable, or is it 1490 // not? If it is then we need a special case here. 1491 if (PC >= current_method->code_length) 1492 verify_fail ("fell off end"); 1493 1494 current_state->stacktop = state::NO_STACK; 1495 push_jump_merge (PC, current_state); 1576 // at this point PC points to the instruction after the jsr. Note 1577 // that it is ok to have a `jsr' at the end of the bytecode, 1578 // provided that the called subroutine never returns. So, we have 1579 // a special case here and another one when we handle the ret. 1580 if (PC < current_method->code_length) 1581 { 1582 current_state->stacktop = state::NO_STACK; 1583 push_jump_merge (PC, current_state); 1584 } 1496 1585 invalidate_pc (); 1497 1586 } … … 1526 1615 k = JvPrimClass (long); 1527 1616 break; 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1528 1630 default: 1529 1631 verify_fail ("unknown type in construct_primitive_array_type"); … … 1829 1931 break; 1830 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1831 1957 default: 1832 1958 verify_fail ("unrecognized instruction in branch_prepass", … … 1846 1972 for (int i = 0; i < current_method->exc_count; ++i) 1847 1973 { 1848 if (! (flags[exception[i].handler_pc ] & FLAG_INSN_START))1974 if (! (flags[exception[i].handler_pc] & FLAG_INSN_START)) 1849 1975 verify_fail ("exception handler not at instruction start", 1850 exception[i].handler_pc );1851 if (! (flags[exception[i].start_pc ] & FLAG_INSN_START))1976 exception[i].handler_pc); 1977 if (! (flags[exception[i].start_pc] & FLAG_INSN_START)) 1852 1978 verify_fail ("exception start not at instruction start", 1853 exception[i].start_pc );1854 if (exception[i].end_pc != current_method->code_length1855 && ! (flags[exception[i].end_pc ] & FLAG_INSN_START))1979 exception[i].start_pc); 1980 if (exception[i].end_pc != current_method->code_length 1981 && ! (flags[exception[i].end_pc] & FLAG_INSN_START)) 1856 1982 verify_fail ("exception end not at instruction start", 1857 exception[i].end_pc );1858 1859 flags[exception[i].handler_pc ] |= FLAG_BRANCH_TARGET;1983 exception[i].end_pc); 1984 1985 flags[exception[i].handler_pc] |= FLAG_BRANCH_TARGET; 1860 1986 } 1861 1987 } … … 2027 2153 { 2028 2154 int var = 0; 2029 bool is_init = false; 2155 bool is_init = _Jv_equalUtf8Consts (current_method->self->name, 2156 gcj::init_name); 2157 bool is_clinit = _Jv_equalUtf8Consts (current_method->self->name, 2158 gcj::clinit_name); 2030 2159 2031 2160 using namespace java::lang::reflect; … … 2033 2162 { 2034 2163 type kurr (current_class); 2035 if ( _Jv_equalUtf8Consts (current_method->self->name, gcj::init_name))2164 if () 2036 2165 { 2037 2166 kurr.set_uninitialized (type::SELF, this); 2038 2167 is_init = true; 2039 2168 } 2169 2170 2040 2171 set_variable (0, kurr); 2041 2172 current_state->set_this_type (kurr); 2042 2173 ++var; 2174 2175 2176 2177 2178 2043 2179 } 2044 2180 … … 2150 2286 for (int i = 0; i < current_method->exc_count; ++i) 2151 2287 { 2152 if (PC >= exception[i].start_pc && PC < exception[i].end_pc)2288 if (PC >= exception[i].start_pc) 2153 2289 { 2154 2290 type handler (&java::lang::Throwable::class$); 2155 if (exception[i].handler_type != 0)2156 handler = check_class_constant (exception[i].handler_type );2157 push_exception_jump (handler, exception[i].handler_pc );2291 if (exception[i].handler_type != 0) 2292 handler = check_class_constant (exception[i].handler_type); 2293 push_exception_jump (handler, exception[i].handler_pc); 2158 2294 } 2159 2295 } … … 2265 2401 case op_iaload: 2266 2402 pop_type (int_type); 2267 push_type (require_array_type (pop_ type(reference_type),2403 push_type (require_array_type (pop_ (reference_type), 2268 2404 int_type)); 2269 2405 break; 2270 2406 case op_laload: 2271 2407 pop_type (int_type); 2272 push_type (require_array_type (pop_ type(reference_type),2408 push_type (require_array_type (pop_ (reference_type), 2273 2409 long_type)); 2274 2410 break; 2275 2411 case op_faload: 2276 2412 pop_type (int_type); 2277 push_type (require_array_type (pop_ type(reference_type),2413 push_type (require_array_type (pop_ (reference_type), 2278 2414 float_type)); 2279 2415 break; 2280 2416 case op_daload: 2281 2417 pop_type (int_type); 2282 push_type (require_array_type (pop_ type(reference_type),2418 push_type (require_array_type (pop_ (reference_type), 2283 2419 double_type)); 2284 2420 break; 2285 2421 case op_aaload: 2286 2422 pop_type (int_type); 2287 push_type (require_array_type (pop_ type(reference_type),2423 push_type (require_array_type (pop_ (reference_type), 2288 2424 reference_type)); 2289 2425 break; 2290 2426 case op_baload: 2291 2427 pop_type (int_type); 2292 require_array_type (pop_ type(reference_type), byte_type);2428 require_array_type (pop_ (reference_type), byte_type); 2293 2429 push_type (int_type); 2294 2430 break; 2295 2431 case op_caload: 2296 2432 pop_type (int_type); 2297 require_array_type (pop_ type(reference_type), char_type);2433 require_array_type (pop_ (reference_type), char_type); 2298 2434 push_type (int_type); 2299 2435 break; 2300 2436 case op_saload: 2301 2437 pop_type (int_type); 2302 require_array_type (pop_ type(reference_type), short_type);2438 require_array_type (pop_ (reference_type), short_type); 2303 2439 push_type (int_type); 2304 2440 break; … … 2351 2487 pop_type (int_type); 2352 2488 pop_type (int_type); 2353 require_array_type (pop_ type(reference_type), int_type);2489 require_array_type (pop_ (reference_type), int_type); 2354 2490 break; 2355 2491 case op_lastore: 2356 2492 pop_type (long_type); 2357 2493 pop_type (int_type); 2358 require_array_type (pop_ type(reference_type), long_type);2494 require_array_type (pop_ (reference_type), long_type); 2359 2495 break; 2360 2496 case op_fastore: 2361 2497 pop_type (float_type); 2362 2498 pop_type (int_type); 2363 require_array_type (pop_ type(reference_type), float_type);2499 require_array_type (pop_ (reference_type), float_type); 2364 2500 break; 2365 2501 case op_dastore: 2366 2502 pop_type (double_type); 2367 2503 pop_type (int_type); 2368 require_array_type (pop_ type(reference_type), double_type);2504 require_array_type (pop_ (reference_type), double_type); 2369 2505 break; 2370 2506 case op_aastore: 2371 2507 pop_type (reference_type); 2372 2508 pop_type (int_type); 2373 require_array_type (pop_ type(reference_type), reference_type);2509 require_array_type (pop_ (reference_type), reference_type); 2374 2510 break; 2375 2511 case op_bastore: 2376 2512 pop_type (int_type); 2377 2513 pop_type (int_type); 2378 require_array_type (pop_ type(reference_type), byte_type);2514 require_array_type (pop_ (reference_type), byte_type); 2379 2515 break; 2380 2516 case op_castore: 2381 2517 pop_type (int_type); 2382 2518 pop_type (int_type); 2383 require_array_type (pop_ type(reference_type), char_type);2519 require_array_type (pop_ (reference_type), char_type); 2384 2520 break; 2385 2521 case op_sastore: 2386 2522 pop_type (int_type); 2387 2523 pop_type (int_type); 2388 require_array_type (pop_ type(reference_type), short_type);2524 require_array_type (pop_ (reference_type), short_type); 2389 2525 break; 2390 2526 case op_pop: … … 2392 2528 break; 2393 2529 case op_pop2: 2394 pop64 (); 2530 { 2531 type t = pop_raw (); 2532 if (! t.iswide ()) 2533 pop32 (); 2534 } 2395 2535 break; 2396 2536 case op_dup: … … 2724 2864 break; 2725 2865 case op_areturn: 2726 check_return_type (pop_ type(reference_type));2866 check_return_type (pop_ (reference_type)); 2727 2867 invalidate_pc (); 2728 2868 break; … … 2806 2946 // invokeinterface. 2807 2947 nargs -= arg_types[i].depth (); 2808 pop_ type(arg_types[i]);2948 pop_ (arg_types[i]); 2809 2949 } 2810 2950 … … 2823 2963 type raw = pop_raw (); 2824 2964 bool ok = false; 2825 if (t.compatible (raw, this)) 2965 if (! is_init && ! raw.isinitialized ()) 2966 { 2967 // This is a failure. 2968 } 2969 else if (is_init && raw.isnull ()) 2970 { 2971 // Another failure. 2972 } 2973 else if (t.compatible (raw, this)) 2826 2974 { 2827 2975 ok = true; … … 2879 3027 case op_arraylength: 2880 3028 { 2881 type t = pop_ type(reference_type);3029 type t = pop_ (reference_type); 2882 3030 if (! t.isarray () && ! t.isnull ()) 2883 3031 verify_fail ("array type expected"); … … 2890 3038 break; 2891 3039 case op_checkcast: 2892 pop_ type(reference_type);3040 pop_ (reference_type); 2893 3041 push_type (check_class_constant (get_ushort ())); 2894 3042 break; 2895 3043 case op_instanceof: 2896 pop_ type(reference_type);3044 pop_ (reference_type); 2897 3045 check_class_constant (get_ushort ()); 2898 3046 push_type (int_type); 2899 3047 break; 2900 3048 case op_monitorenter: 2901 pop_ type(reference_type);3049 pop_ (reference_type); 2902 3050 break; 2903 3051 case op_monitorexit: 2904 pop_ type(reference_type);3052 pop_ (reference_type); 2905 3053 break; 2906 3054 case op_wide: … … 2936 3084 break; 2937 3085 case op_astore: 2938 set_variable (get_ushort (), pop_ type(reference_type));3086 set_variable (get_ushort (), pop_ (reference_type)); 2939 3087 break; 2940 3088 case op_ret: … … 2975 3123 break; 2976 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 2977 3149 default: 2978 3150 // Unrecognized opcode. … … 2981 3153 } 2982 3154 } 2983 }2984 2985 __attribute__ ((__noreturn__)) void verify_fail (char *s, jint pc = -1)2986 {2987 using namespace java::lang;2988 StringBuffer *buf = new StringBuffer ();2989 2990 buf->append (JvNewStringLatin1 ("verification failed"));2991 if (pc == -1)2992 pc = start_PC;2993 if (pc != -1)2994 {2995 buf->append (JvNewStringLatin1 (" at PC "));2996 buf->append (pc);2997 }2998 2999 _Jv_InterpMethod *method = current_method;3000 buf->append (JvNewStringLatin1 (" in "));3001 buf->append (current_class->getName());3002 buf->append ((jchar) ':');3003 buf->append (JvNewStringUTF (method->get_method()->name->data));3004 buf->append ((jchar) '(');3005 buf->append (JvNewStringUTF (method->get_method()->signature->data));3006 buf->append ((jchar) ')');3007 3008 buf->append (JvNewStringLatin1 (": "));3009 buf->append (JvNewStringLatin1 (s));3010 throw new java::lang::VerifyError (buf->toString ());3011 3155 } 3012 3156 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
