Mercurial > hg > truffle
comparison src/share/vm/prims/jvm.cpp @ 665:c89f86385056
6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never
author | jrose |
---|---|
date | Fri, 20 Mar 2009 23:19:36 -0700 |
parents | 0fbdb4381b99 |
children | d3676b4cb78c |
comparison
equal
deleted
inserted
replaced
647:bd441136a5ce | 665:c89f86385056 |
---|---|
1240 klassOop ik = cp->klass_at(ioff, CHECK_NULL); | 1240 klassOop ik = cp->klass_at(ioff, CHECK_NULL); |
1241 instanceKlassHandle inner_klass (THREAD, ik); | 1241 instanceKlassHandle inner_klass (THREAD, ik); |
1242 | 1242 |
1243 // Throws an exception if outer klass has not declared k as | 1243 // Throws an exception if outer klass has not declared k as |
1244 // an inner klass | 1244 // an inner klass |
1245 Reflection::check_for_inner_class(k, inner_klass, CHECK_NULL); | 1245 Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL); |
1246 | 1246 |
1247 result->obj_at_put(members, inner_klass->java_mirror()); | 1247 result->obj_at_put(members, inner_klass->java_mirror()); |
1248 members++; | 1248 members++; |
1249 } | 1249 } |
1250 } | 1250 } |
1263 return (jobjectArray)JNIHandles::make_local(env, result()); | 1263 return (jobjectArray)JNIHandles::make_local(env, result()); |
1264 JVM_END | 1264 JVM_END |
1265 | 1265 |
1266 | 1266 |
1267 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) | 1267 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) |
1268 const int inner_class_info_index = 0; | 1268 { |
1269 const int outer_class_info_index = 1; | |
1270 | |
1271 // ofClass is a reference to a java_lang_Class object. | 1269 // ofClass is a reference to a java_lang_Class object. |
1272 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || | 1270 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
1273 ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) { | 1271 ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) { |
1274 return NULL; | 1272 return NULL; |
1275 } | 1273 } |
1276 | 1274 |
1277 instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass))); | 1275 symbolOop simple_name = NULL; |
1276 klassOop outer_klass | |
1277 = instanceKlass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)) | |
1278 )->compute_enclosing_class(simple_name, CHECK_NULL); | |
1279 if (outer_klass == NULL) return NULL; // already a top-level class | |
1280 if (simple_name == NULL) return NULL; // an anonymous class (inside a method) | |
1281 return (jclass) JNIHandles::make_local(env, Klass::cast(outer_klass)->java_mirror()); | |
1282 } | |
1283 JVM_END | |
1284 | |
1285 // should be in instanceKlass.cpp, but is here for historical reasons | |
1286 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, | |
1287 symbolOop& simple_name_result, TRAPS) { | |
1288 Thread* thread = THREAD; | |
1289 const int inner_class_info_index = inner_class_inner_class_info_offset; | |
1290 const int outer_class_info_index = inner_class_outer_class_info_offset; | |
1278 | 1291 |
1279 if (k->inner_classes()->length() == 0) { | 1292 if (k->inner_classes()->length() == 0) { |
1280 // No inner class info => no declaring class | 1293 // No inner class info => no declaring class |
1281 return NULL; | 1294 return NULL; |
1282 } | 1295 } |
1286 int i_length = i_icls->length(); | 1299 int i_length = i_icls->length(); |
1287 | 1300 |
1288 bool found = false; | 1301 bool found = false; |
1289 klassOop ok; | 1302 klassOop ok; |
1290 instanceKlassHandle outer_klass; | 1303 instanceKlassHandle outer_klass; |
1304 bool inner_is_member = false; | |
1305 int simple_name_index = 0; | |
1291 | 1306 |
1292 // Find inner_klass attribute | 1307 // Find inner_klass attribute |
1293 for(int i = 0; i < i_length && !found; i+= 4) { | 1308 for (int i = 0; i < i_length && !found; i += inner_class_next_offset) { |
1294 int ioff = i_icls->ushort_at(i + inner_class_info_index); | 1309 int ioff = i_icls->ushort_at(i + inner_class_info_index); |
1295 int ooff = i_icls->ushort_at(i + outer_class_info_index); | 1310 int ooff = i_icls->ushort_at(i + outer_class_info_index); |
1296 | 1311 int noff = i_icls->ushort_at(i + inner_class_inner_name_offset); |
1297 if (ioff != 0 && ooff != 0) { | 1312 if (ioff != 0) { |
1298 // Check to see if the name matches the class we're looking for | 1313 // Check to see if the name matches the class we're looking for |
1299 // before attempting to find the class. | 1314 // before attempting to find the class. |
1300 if (i_cp->klass_name_at_matches(k, ioff)) { | 1315 if (i_cp->klass_name_at_matches(k, ioff)) { |
1301 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL); | 1316 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL); |
1302 if (k() == inner_klass) { | 1317 found = (k() == inner_klass); |
1303 found = true; | 1318 if (found && ooff != 0) { |
1304 ok = i_cp->klass_at(ooff, CHECK_NULL); | 1319 ok = i_cp->klass_at(ooff, CHECK_NULL); |
1305 outer_klass = instanceKlassHandle(thread, ok); | 1320 outer_klass = instanceKlassHandle(thread, ok); |
1321 simple_name_index = noff; | |
1322 inner_is_member = true; | |
1306 } | 1323 } |
1307 } | 1324 } |
1308 } | 1325 } |
1309 } | 1326 } |
1310 | 1327 |
1328 if (found && outer_klass.is_null()) { | |
1329 // It may be anonymous; try for that. | |
1330 int encl_method_class_idx = k->enclosing_method_class_index(); | |
1331 if (encl_method_class_idx != 0) { | |
1332 ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL); | |
1333 outer_klass = instanceKlassHandle(thread, ok); | |
1334 inner_is_member = false; | |
1335 } | |
1336 } | |
1337 | |
1311 // If no inner class attribute found for this class. | 1338 // If no inner class attribute found for this class. |
1312 if (!found) return NULL; | 1339 if (outer_klass.is_null()) return NULL; |
1313 | 1340 |
1314 // Throws an exception if outer klass has not declared k as an inner klass | 1341 // Throws an exception if outer klass has not declared k as an inner klass |
1315 Reflection::check_for_inner_class(outer_klass, k, CHECK_NULL); | 1342 // We need evidence that each klass knows about the other, or else |
1316 | 1343 // the system could allow a spoof of an inner class to gain access rights. |
1317 return (jclass)JNIHandles::make_local(env, outer_klass->java_mirror()); | 1344 Reflection::check_for_inner_class(outer_klass, k, inner_is_member, CHECK_NULL); |
1318 JVM_END | 1345 |
1319 | 1346 simple_name_result = (inner_is_member ? i_cp->symbol_at(simple_name_index) : symbolOop(NULL)); |
1347 return outer_klass(); | |
1348 } | |
1320 | 1349 |
1321 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) | 1350 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) |
1322 assert (cls != NULL, "illegal class"); | 1351 assert (cls != NULL, "illegal class"); |
1323 JVMWrapper("JVM_GetClassSignature"); | 1352 JVMWrapper("JVM_GetClassSignature"); |
1324 JvmtiVMObjectAllocEventCollector oam; | 1353 JvmtiVMObjectAllocEventCollector oam; |