< prev index next >

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Print this page

1264         if (vf->is_compiled_frame()) {
1265           // compiled method frame
1266           compiledVFrame* cvf = compiledVFrame::cast(vf);
1267 
1268           ScopeDesc* scope = cvf->scope();
1269           // native wrappers do not have a scope
1270           if (scope != NULL && scope->objects() != NULL) {
1271             prev_cvf = cvf;
1272 
1273             GrowableArray<ScopeValue*>* objects = NULL;
1274             if (!realloc_called) {
1275               objects = scope->objects();
1276             } else {
1277               // some object might already have been re-allocated, only reallocate the non-allocated ones
1278               objects = get_unallocated_objects_or_null(scope->objects());
1279             }
1280 
1281             if (objects != NULL) {
1282               RegisterMap reg_map(vf->register_map());
1283               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1284               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1285               realloc_called = true;
1286             }
1287 
1288             GrowableArray<ScopeValue*>* local_values = scope->locals();
1289             for (int i = 0; i < local_values->length(); i++) {
1290               ScopeValue* value = local_values->at(i);
1291               if (value->is_object()) {
1292                 if (localIsVirtual_h.is_null()) {
1293                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1294                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1295                 }
1296                 localIsVirtual_h->bool_at_put(i, true);
1297               }
1298             }
1299           }
1300 
1301           locals = cvf->locals();
1302           frame_number = cvf->vframe_id();
1303         } else {
1304           // interpreted method frame

1496       break;
1497     }
1498     vf = vf->sender();
1499   }
1500 
1501   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1502   if (last_frame_number >= virtualFrames->length()) {
1503     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1504   }
1505 
1506   // Reallocate the non-escaping objects and restore their fields.
1507   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1508   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1509 
1510   if (objects == NULL) {
1511     // no objects to materialize
1512     return;
1513   }
1514 
1515   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1516   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1517 
1518   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1519     compiledVFrame* cvf = virtualFrames->at(frame_index);
1520 
1521     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1522     StackValueCollection* locals = cvf->locals();
1523     if (locals != NULL) {
1524       for (int i2 = 0; i2 < locals->size(); i2++) {
1525         StackValue* var = locals->at(i2);
1526         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1527           jvalue val;
1528           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1529           cvf->update_local(T_OBJECT, i2, val);
1530         }
1531       }
1532     }
1533 
1534     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1535     StackValueCollection* expressions = cvf->expressions();
1536     if (expressions != NULL) {

1809   return JVMCIENV->get_jobject(result);
1810 C2V_END
1811 
1812 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, jobject holder))
1813   if (holder == NULL) {
1814     JVMCI_THROW_0(NullPointerException);
1815   }
1816   Klass* klass = JVMCIENV->asKlass(holder);
1817   if (!klass->is_instance_klass()) {
1818     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1819     return JVMCIENV->get_jobjectArray(methods);
1820   }
1821 
1822   InstanceKlass* iklass = InstanceKlass::cast(klass);
1823   // Ensure class is linked
1824   iklass->link_class(CHECK_NULL);
1825 
1826   GrowableArray<Method*> constructors_array;
1827   for (int i = 0; i < iklass->methods()->length(); i++) {
1828     Method* m = iklass->methods()->at(i);
1829     if (m->is_initializer() && !m->is_static()) {
1830       constructors_array.append(m);
1831     }
1832   }
1833   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1834   for (int i = 0; i < constructors_array.length(); i++) {
1835     methodHandle ctor(THREAD, constructors_array.at(i));
1836     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1837     JVMCIENV->put_object_at(methods, i, method);
1838   }
1839   return JVMCIENV->get_jobjectArray(methods);
1840 C2V_END
1841 
1842 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, jobject holder))
1843   if (holder == NULL) {
1844     JVMCI_THROW_0(NullPointerException);
1845   }
1846   Klass* klass = JVMCIENV->asKlass(holder);
1847   if (!klass->is_instance_klass()) {
1848     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1849     return JVMCIENV->get_jobjectArray(methods);
1850   }
1851 
1852   InstanceKlass* iklass = InstanceKlass::cast(klass);
1853   // Ensure class is linked
1854   iklass->link_class(CHECK_NULL);
1855 
1856   GrowableArray<Method*> methods_array;
1857   for (int i = 0; i < iklass->methods()->length(); i++) {
1858     Method* m = iklass->methods()->at(i);
1859     if (!m->is_initializer() && !m->is_overpass()) {
1860       methods_array.append(m);
1861     }
1862   }
1863   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1864   for (int i = 0; i < methods_array.length(); i++) {
1865     methodHandle mh(THREAD, methods_array.at(i));
1866     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1867     JVMCIENV->put_object_at(methods, i, method);
1868   }
1869   return JVMCIENV->get_jobjectArray(methods);
1870 C2V_END
1871 
1872 C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, jobject expected_type, jlong displacement, jobject kind_object))
1873   if (object == NULL || kind_object == NULL) {
1874     JVMCI_THROW_0(NullPointerException);
1875   }
1876 
1877   JVMCIObject kind = JVMCIENV->wrap(kind_object);
1878   BasicType basic_type = JVMCIENV->kindToBasicType(kind, JVMCI_CHECK_NULL);
1879 

2473   JVMCIENV->get_nmethod(code, locker);
2474 }
2475 
2476 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2477   JVMCIObject code = JVMCIENV->wrap(code_handle);
2478   nmethodLocker locker;
2479   CodeBlob* cb = JVMCIENV->get_code_blob(code, locker);
2480   if (cb == NULL) {
2481     return NULL;
2482   }
2483   int code_size = cb->code_size();
2484   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2485   JVMCIENV->copy_bytes_from((jbyte*) cb->code_begin(), result, 0, code_size);
2486   return JVMCIENV->get_jbyteArray(result);
2487 }
2488 
2489 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, jobject jvmci_method))
2490   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2491   methodHandle m(THREAD, JVMCIENV->asMethod(jvmci_method));
2492   oop executable;
2493   if (m->is_initializer()) {
2494     if (m->is_static_initializer()) {
2495       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2496           "Cannot create java.lang.reflect.Method for class initializer");
2497     }

2498     executable = Reflection::new_constructor(m, CHECK_NULL);
2499   } else {
2500     executable = Reflection::new_method(m, false, CHECK_NULL);
2501   }
2502   return JNIHandles::make_local(THREAD, executable);
2503 }
2504 
2505 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, jobject jvmci_type, jint index))
2506   requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2507   Klass* klass = JVMCIENV->asKlass(jvmci_type);
2508   if (!klass->is_instance_klass()) {
2509     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2510         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2511   }
2512   InstanceKlass* iklass = InstanceKlass::cast(klass);
2513   Array<u2>* fields = iklass->fields();
2514   if (index < 0 ||index > fields->length()) {
2515     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2516         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2517   }

1264         if (vf->is_compiled_frame()) {
1265           // compiled method frame
1266           compiledVFrame* cvf = compiledVFrame::cast(vf);
1267 
1268           ScopeDesc* scope = cvf->scope();
1269           // native wrappers do not have a scope
1270           if (scope != NULL && scope->objects() != NULL) {
1271             prev_cvf = cvf;
1272 
1273             GrowableArray<ScopeValue*>* objects = NULL;
1274             if (!realloc_called) {
1275               objects = scope->objects();
1276             } else {
1277               // some object might already have been re-allocated, only reallocate the non-allocated ones
1278               objects = get_unallocated_objects_or_null(scope->objects());
1279             }
1280 
1281             if (objects != NULL) {
1282               RegisterMap reg_map(vf->register_map());
1283               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1284               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false, CHECK_NULL);
1285               realloc_called = true;
1286             }
1287 
1288             GrowableArray<ScopeValue*>* local_values = scope->locals();
1289             for (int i = 0; i < local_values->length(); i++) {
1290               ScopeValue* value = local_values->at(i);
1291               if (value->is_object()) {
1292                 if (localIsVirtual_h.is_null()) {
1293                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1294                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1295                 }
1296                 localIsVirtual_h->bool_at_put(i, true);
1297               }
1298             }
1299           }
1300 
1301           locals = cvf->locals();
1302           frame_number = cvf->vframe_id();
1303         } else {
1304           // interpreted method frame

1496       break;
1497     }
1498     vf = vf->sender();
1499   }
1500 
1501   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1502   if (last_frame_number >= virtualFrames->length()) {
1503     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1504   }
1505 
1506   // Reallocate the non-escaping objects and restore their fields.
1507   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1508   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1509 
1510   if (objects == NULL) {
1511     // no objects to materialize
1512     return;
1513   }
1514 
1515   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1516   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1517 
1518   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1519     compiledVFrame* cvf = virtualFrames->at(frame_index);
1520 
1521     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1522     StackValueCollection* locals = cvf->locals();
1523     if (locals != NULL) {
1524       for (int i2 = 0; i2 < locals->size(); i2++) {
1525         StackValue* var = locals->at(i2);
1526         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1527           jvalue val;
1528           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1529           cvf->update_local(T_OBJECT, i2, val);
1530         }
1531       }
1532     }
1533 
1534     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1535     StackValueCollection* expressions = cvf->expressions();
1536     if (expressions != NULL) {

1809   return JVMCIENV->get_jobject(result);
1810 C2V_END
1811 
1812 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, jobject holder))
1813   if (holder == NULL) {
1814     JVMCI_THROW_0(NullPointerException);
1815   }
1816   Klass* klass = JVMCIENV->asKlass(holder);
1817   if (!klass->is_instance_klass()) {
1818     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1819     return JVMCIENV->get_jobjectArray(methods);
1820   }
1821 
1822   InstanceKlass* iklass = InstanceKlass::cast(klass);
1823   // Ensure class is linked
1824   iklass->link_class(CHECK_NULL);
1825 
1826   GrowableArray<Method*> constructors_array;
1827   for (int i = 0; i < iklass->methods()->length(); i++) {
1828     Method* m = iklass->methods()->at(i);
1829     if (m->is_object_constructor()) {
1830       constructors_array.append(m);
1831     }
1832   }
1833   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1834   for (int i = 0; i < constructors_array.length(); i++) {
1835     methodHandle ctor(THREAD, constructors_array.at(i));
1836     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1837     JVMCIENV->put_object_at(methods, i, method);
1838   }
1839   return JVMCIENV->get_jobjectArray(methods);
1840 C2V_END
1841 
1842 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, jobject holder))
1843   if (holder == NULL) {
1844     JVMCI_THROW_0(NullPointerException);
1845   }
1846   Klass* klass = JVMCIENV->asKlass(holder);
1847   if (!klass->is_instance_klass()) {
1848     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1849     return JVMCIENV->get_jobjectArray(methods);
1850   }
1851 
1852   InstanceKlass* iklass = InstanceKlass::cast(klass);
1853   // Ensure class is linked
1854   iklass->link_class(CHECK_NULL);
1855 
1856   GrowableArray<Method*> methods_array;
1857   for (int i = 0; i < iklass->methods()->length(); i++) {
1858     Method* m = iklass->methods()->at(i);
1859     if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
1860       methods_array.append(m);
1861     }
1862   }
1863   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1864   for (int i = 0; i < methods_array.length(); i++) {
1865     methodHandle mh(THREAD, methods_array.at(i));
1866     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1867     JVMCIENV->put_object_at(methods, i, method);
1868   }
1869   return JVMCIENV->get_jobjectArray(methods);
1870 C2V_END
1871 
1872 C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, jobject expected_type, jlong displacement, jobject kind_object))
1873   if (object == NULL || kind_object == NULL) {
1874     JVMCI_THROW_0(NullPointerException);
1875   }
1876 
1877   JVMCIObject kind = JVMCIENV->wrap(kind_object);
1878   BasicType basic_type = JVMCIENV->kindToBasicType(kind, JVMCI_CHECK_NULL);
1879 

2473   JVMCIENV->get_nmethod(code, locker);
2474 }
2475 
2476 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2477   JVMCIObject code = JVMCIENV->wrap(code_handle);
2478   nmethodLocker locker;
2479   CodeBlob* cb = JVMCIENV->get_code_blob(code, locker);
2480   if (cb == NULL) {
2481     return NULL;
2482   }
2483   int code_size = cb->code_size();
2484   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2485   JVMCIENV->copy_bytes_from((jbyte*) cb->code_begin(), result, 0, code_size);
2486   return JVMCIENV->get_jbyteArray(result);
2487 }
2488 
2489 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, jobject jvmci_method))
2490   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2491   methodHandle m(THREAD, JVMCIENV->asMethod(jvmci_method));
2492   oop executable;
2493   if (m->is_class_initializer()) {

2494       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2495           "Cannot create java.lang.reflect.Method for class initializer");
2496   }
2497   else if (m->is_object_constructor() || m->is_static_init_factory()) {
2498     executable = Reflection::new_constructor(m, CHECK_NULL);
2499   } else {
2500     executable = Reflection::new_method(m, false, CHECK_NULL);
2501   }
2502   return JNIHandles::make_local(THREAD, executable);
2503 }
2504 
2505 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, jobject jvmci_type, jint index))
2506   requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2507   Klass* klass = JVMCIENV->asKlass(jvmci_type);
2508   if (!klass->is_instance_klass()) {
2509     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2510         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2511   }
2512   InstanceKlass* iklass = InstanceKlass::cast(klass);
2513   Array<u2>* fields = iklass->fields();
2514   if (index < 0 ||index > fields->length()) {
2515     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2516         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2517   }
< prev index next >