Changeset 1391 for branches/GNU/src/gcc/libjava/verify.cc
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 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.1
to1.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, 2003 Free Software Foundation 4 4 5 5 This file is part of libgcj. … … 127 127 128 128 return r; 129 } 130 131 __attribute__ ((__noreturn__)) void verify_fail (char *s, jint pc = -1) 132 { 133 using namespace java::lang; 134 StringBuffer *buf = new StringBuffer (); 135 136 buf->append (JvNewStringLatin1 ("verification failed")); 137 if (pc == -1) 138 pc = start_PC; 139 if (pc != -1) 140 { 141 buf->append (JvNewStringLatin1 (" at PC ")); 142 buf->append (pc); 143 } 144 145 _Jv_InterpMethod *method = current_method; 146 buf->append (JvNewStringLatin1 (" in ")); 147 buf->append (current_class->getName()); 148 buf->append ((jchar) ':'); 149 buf->append (JvNewStringUTF (method->get_method()->name->data)); 150 buf->append ((jchar) '('); 151 buf->append (JvNewStringUTF (method->get_method()->signature->data)); 152 buf->append ((jchar) ')'); 153 154 buf->append (JvNewStringLatin1 (": ")); 155 buf->append (JvNewStringLatin1 (s)); 156 throw new java::lang::VerifyError (buf->toString ()); 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->getClassLoaderInternal(); 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 initialized reference 490 // type. 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->getClassLoaderInternal())); 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->getClassLoaderInternal(); 699 727 k = _Jv_GetArrayClass (k, loader); 700 728 --arraycount; … … 794 822 // without really initializing. 795 823 type this_type; 824 // This is a list of all subroutines that have been seen at this 825 // point. Ordinarily this is NULL; it is only allocated and used 826 // in relatively weird situations involving non-ret exit from a 827 // subroutine. We have to keep track of this in this way to avoid 828 // endless recursion in these cases. 829 subr_info *seen_subrs; 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 seen_subrs = NULL; 814 849 } 815 850 … … 824 859 locals = new type[max_locals]; 825 860 local_changed = (bool *) _Jv_Malloc (sizeof (bool) * max_locals); 861 seen_subrs = NULL; 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 seen_subrs = NULL; 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 clean_subrs (); 853 891 } 854 892 … … 871 909 { 872 910 _Jv_Free (mem); 911 } 912 913 void clean_subrs () 914 { 915 subr_info *info = seen_subrs; 916 while (info != NULL) 917 { 918 subr_info *next = info->next; 919 _Jv_Free (info); 920 info = next; 921 } 873 922 } 874 923 … … 892 941 local_changed[i] = copy->local_changed[i]; 893 942 } 943 944 clean_subrs (); 945 if (copy->seen_subrs) 946 { 947 for (subr_info *info = seen_subrs; info != NULL; info = info->next) 948 add_subr (info->pc); 949 } 950 else 951 seen_subrs = NULL; 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 // Indicate that we've been in this this subroutine. 980 void add_subr (int pc) 981 { 982 subr_info *n = (subr_info *) _Jv_Malloc (sizeof (subr_info)); 983 n->pc = pc; 984 n->next = seen_subrs; 985 seen_subrs = n; 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 verify_fail ("incompatible type on stack"); 1211 return t; 1212 } 1213 1214 // Pop a reference which is guaranteed to be initialized. MATCH 1215 // doesn't have to be a reference type; in this case this acts like 1216 // pop_type. 1217 type pop_init_ref (type match) 1218 { 1219 type t = pop_raw (); 1220 if (t.isreference () && ! t.isinitialized ()) 1221 verify_fail ("initialized reference required"); 1222 else if (! match.compatible (t, this)) 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 // We might be returning to a `jsr' that is at the end of the 1522 // bytecode. This is ok if we never return from the called 1523 // subroutine, but if we see this here it is an error. 1524 if (subr->pc >= current_method->code_length) 1525 verify_fail ("fell off end"); 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 // These aren't used here but we call them out to avoid 1619 // warnings. 1620 case void_type: 1621 case unsuitable_type: 1622 case return_address_type: 1623 case continuation_type: 1624 case unused_by_subroutine_type: 1625 case reference_type: 1626 case null_type: 1627 case unresolved_reference_type: 1628 case uninitialized_reference_type: 1629 case uninitialized_unresolved_reference_type: 1528 1630 default: 1529 1631 verify_fail ("unknown type in construct_primitive_array_type"); … … 1829 1931 break; 1830 1932 1933 // These are unused here, but we call them out explicitly 1934 // so that -Wswitch-enum doesn't complain. 1935 case op_putfield_1: 1936 case op_putfield_2: 1937 case op_putfield_4: 1938 case op_putfield_8: 1939 case op_putfield_a: 1940 case op_putstatic_1: 1941 case op_putstatic_2: 1942 case op_putstatic_4: 1943 case op_putstatic_8: 1944 case op_putstatic_a: 1945 case op_getfield_1: 1946 case op_getfield_2s: 1947 case op_getfield_2u: 1948 case op_getfield_4: 1949 case op_getfield_8: 1950 case op_getfield_a: 1951 case op_getstatic_1: 1952 case op_getstatic_2s: 1953 case op_getstatic_2u: 1954 case op_getstatic_4: 1955 case op_getstatic_8: 1956 case op_getstatic_a: 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.i] & 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.i); 1977 if (! (flags[exception[i].start_pc.i] & 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.i); 1980 if (exception[i].end_pc.i != current_method->code_length 1981 && ! (flags[exception[i].end_pc.i] & 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.i); 1984 1985 flags[exception[i].handler_pc.i] |= 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 (is_init) 2036 2165 { 2037 2166 kurr.set_uninitialized (type::SELF, this); 2038 2167 is_init = true; 2039 2168 } 2169 else if (is_clinit) 2170 verify_fail ("<clinit> method must be static"); 2040 2171 set_variable (0, kurr); 2041 2172 current_state->set_this_type (kurr); 2042 2173 ++var; 2174 } 2175 else 2176 { 2177 if (is_init) 2178 verify_fail ("<init> method must be non-static"); 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.i && PC < exception[i].end_pc.i) 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.i != 0) 2292 handler = check_class_constant (exception[i].handler_type.i); 2293 push_exception_jump (handler, exception[i].handler_pc.i); 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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (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_init_ref (reference_type); 2902 3050 break; 2903 3051 case op_monitorexit: 2904 pop_ type(reference_type);3052 pop_init_ref (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_init_ref (reference_type)); 2939 3087 break; 2940 3088 case op_ret: … … 2975 3123 break; 2976 3124 3125 // These are unused here, but we call them out explicitly 3126 // so that -Wswitch-enum doesn't complain. 3127 case op_putfield_1: 3128 case op_putfield_2: 3129 case op_putfield_4: 3130 case op_putfield_8: 3131 case op_putfield_a: 3132 case op_putstatic_1: 3133 case op_putstatic_2: 3134 case op_putstatic_4: 3135 case op_putstatic_8: 3136 case op_putstatic_a: 3137 case op_getfield_1: 3138 case op_getfield_2s: 3139 case op_getfield_2u: 3140 case op_getfield_4: 3141 case op_getfield_8: 3142 case op_getfield_a: 3143 case op_getstatic_1: 3144 case op_getstatic_2s: 3145 case op_getstatic_2u: 3146 case op_getstatic_4: 3147 case op_getstatic_8: 3148 case op_getstatic_a: 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.