Mercurial > hg > truffle
comparison src/share/vm/prims/jvm.cpp @ 676:d3676b4cb78c
Merge
author | kvn |
---|---|
date | Tue, 31 Mar 2009 10:02:01 -0700 |
parents | 715dceaa89b7 c89f86385056 |
children | be93aad57795 |
comparison
equal
deleted
inserted
replaced
662:9ab385cb0c42 | 676:d3676b4cb78c |
---|---|
1250 klassOop ik = cp->klass_at(ioff, CHECK_NULL); | 1250 klassOop ik = cp->klass_at(ioff, CHECK_NULL); |
1251 instanceKlassHandle inner_klass (THREAD, ik); | 1251 instanceKlassHandle inner_klass (THREAD, ik); |
1252 | 1252 |
1253 // Throws an exception if outer klass has not declared k as | 1253 // Throws an exception if outer klass has not declared k as |
1254 // an inner klass | 1254 // an inner klass |
1255 Reflection::check_for_inner_class(k, inner_klass, CHECK_NULL); | 1255 Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL); |
1256 | 1256 |
1257 result->obj_at_put(members, inner_klass->java_mirror()); | 1257 result->obj_at_put(members, inner_klass->java_mirror()); |
1258 members++; | 1258 members++; |
1259 } | 1259 } |
1260 } | 1260 } |
1273 return (jobjectArray)JNIHandles::make_local(env, result()); | 1273 return (jobjectArray)JNIHandles::make_local(env, result()); |
1274 JVM_END | 1274 JVM_END |
1275 | 1275 |
1276 | 1276 |
1277 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) | 1277 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) |
1278 const int inner_class_info_index = 0; | 1278 { |
1279 const int outer_class_info_index = 1; | |
1280 | |
1281 // ofClass is a reference to a java_lang_Class object. | 1279 // ofClass is a reference to a java_lang_Class object. |
1282 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || | 1280 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
1283 ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) { | 1281 ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) { |
1284 return NULL; | 1282 return NULL; |
1285 } | 1283 } |
1286 | 1284 |
1287 instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass))); | 1285 symbolOop simple_name = NULL; |
1286 klassOop outer_klass | |
1287 = instanceKlass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)) | |
1288 )->compute_enclosing_class(simple_name, CHECK_NULL); | |
1289 if (outer_klass == NULL) return NULL; // already a top-level class | |
1290 if (simple_name == NULL) return NULL; // an anonymous class (inside a method) | |
1291 return (jclass) JNIHandles::make_local(env, Klass::cast(outer_klass)->java_mirror()); | |
1292 } | |
1293 JVM_END | |
1294 | |
1295 // should be in instanceKlass.cpp, but is here for historical reasons | |
1296 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, | |
1297 symbolOop& simple_name_result, TRAPS) { | |
1298 Thread* thread = THREAD; | |
1299 const int inner_class_info_index = inner_class_inner_class_info_offset; | |
1300 const int outer_class_info_index = inner_class_outer_class_info_offset; | |
1288 | 1301 |
1289 if (k->inner_classes()->length() == 0) { | 1302 if (k->inner_classes()->length() == 0) { |
1290 // No inner class info => no declaring class | 1303 // No inner class info => no declaring class |
1291 return NULL; | 1304 return NULL; |
1292 } | 1305 } |
1296 int i_length = i_icls->length(); | 1309 int i_length = i_icls->length(); |
1297 | 1310 |
1298 bool found = false; | 1311 bool found = false; |
1299 klassOop ok; | 1312 klassOop ok; |
1300 instanceKlassHandle outer_klass; | 1313 instanceKlassHandle outer_klass; |
1314 bool inner_is_member = false; | |
1315 int simple_name_index = 0; | |
1301 | 1316 |
1302 // Find inner_klass attribute | 1317 // Find inner_klass attribute |
1303 for(int i = 0; i < i_length && !found; i+= 4) { | 1318 for (int i = 0; i < i_length && !found; i += inner_class_next_offset) { |
1304 int ioff = i_icls->ushort_at(i + inner_class_info_index); | 1319 int ioff = i_icls->ushort_at(i + inner_class_info_index); |
1305 int ooff = i_icls->ushort_at(i + outer_class_info_index); | 1320 int ooff = i_icls->ushort_at(i + outer_class_info_index); |
1306 | 1321 int noff = i_icls->ushort_at(i + inner_class_inner_name_offset); |
1307 if (ioff != 0 && ooff != 0) { | 1322 if (ioff != 0) { |
1308 // Check to see if the name matches the class we're looking for | 1323 // Check to see if the name matches the class we're looking for |
1309 // before attempting to find the class. | 1324 // before attempting to find the class. |
1310 if (i_cp->klass_name_at_matches(k, ioff)) { | 1325 if (i_cp->klass_name_at_matches(k, ioff)) { |
1311 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL); | 1326 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL); |
1312 if (k() == inner_klass) { | 1327 found = (k() == inner_klass); |
1313 found = true; | 1328 if (found && ooff != 0) { |
1314 ok = i_cp->klass_at(ooff, CHECK_NULL); | 1329 ok = i_cp->klass_at(ooff, CHECK_NULL); |
1315 outer_klass = instanceKlassHandle(thread, ok); | 1330 outer_klass = instanceKlassHandle(thread, ok); |
1331 simple_name_index = noff; | |
1332 inner_is_member = true; | |
1316 } | 1333 } |
1317 } | 1334 } |
1318 } | 1335 } |
1319 } | 1336 } |
1320 | 1337 |
1338 if (found && outer_klass.is_null()) { | |
1339 // It may be anonymous; try for that. | |
1340 int encl_method_class_idx = k->enclosing_method_class_index(); | |
1341 if (encl_method_class_idx != 0) { | |
1342 ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL); | |
1343 outer_klass = instanceKlassHandle(thread, ok); | |
1344 inner_is_member = false; | |
1345 } | |
1346 } | |
1347 | |
1321 // If no inner class attribute found for this class. | 1348 // If no inner class attribute found for this class. |
1322 if (!found) return NULL; | 1349 if (outer_klass.is_null()) return NULL; |
1323 | 1350 |
1324 // Throws an exception if outer klass has not declared k as an inner klass | 1351 // Throws an exception if outer klass has not declared k as an inner klass |
1325 Reflection::check_for_inner_class(outer_klass, k, CHECK_NULL); | 1352 // We need evidence that each klass knows about the other, or else |
1326 | 1353 // the system could allow a spoof of an inner class to gain access rights. |
1327 return (jclass)JNIHandles::make_local(env, outer_klass->java_mirror()); | 1354 Reflection::check_for_inner_class(outer_klass, k, inner_is_member, CHECK_NULL); |
1328 JVM_END | 1355 |
1329 | 1356 simple_name_result = (inner_is_member ? i_cp->symbol_at(simple_name_index) : symbolOop(NULL)); |
1357 return outer_klass(); | |
1358 } | |
1330 | 1359 |
1331 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) | 1360 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) |
1332 assert (cls != NULL, "illegal class"); | 1361 assert (cls != NULL, "illegal class"); |
1333 JVMWrapper("JVM_GetClassSignature"); | 1362 JVMWrapper("JVM_GetClassSignature"); |
1334 JvmtiVMObjectAllocEventCollector oam; | 1363 JvmtiVMObjectAllocEventCollector oam; |