< prev index next >

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Print this page

1286         if (vf->is_compiled_frame()) {
1287           // compiled method frame
1288           compiledVFrame* cvf = compiledVFrame::cast(vf);
1289 
1290           ScopeDesc* scope = cvf->scope();
1291           // native wrappers do not have a scope
1292           if (scope != NULL && scope->objects() != NULL) {
1293             prev_cvf = cvf;
1294 
1295             GrowableArray<ScopeValue*>* objects = NULL;
1296             if (!realloc_called) {
1297               objects = scope->objects();
1298             } else {
1299               // some object might already have been re-allocated, only reallocate the non-allocated ones
1300               objects = get_unallocated_objects_or_null(scope->objects());
1301             }
1302 
1303             if (objects != NULL) {
1304               RegisterMap reg_map(vf->register_map());
1305               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1306               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1307               realloc_called = true;
1308             }
1309 
1310             GrowableArray<ScopeValue*>* local_values = scope->locals();
1311             for (int i = 0; i < local_values->length(); i++) {
1312               ScopeValue* value = local_values->at(i);
1313               if (value->is_object()) {
1314                 if (localIsVirtual_h.is_null()) {
1315                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1316                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1317                 }
1318                 localIsVirtual_h->bool_at_put(i, true);
1319               }
1320             }
1321           }
1322 
1323           locals = cvf->locals();
1324           frame_number = cvf->vframe_id();
1325         } else {
1326           // interpreted method frame

1518       break;
1519     }
1520     vf = vf->sender();
1521   }
1522 
1523   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1524   if (last_frame_number >= virtualFrames->length()) {
1525     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1526   }
1527 
1528   // Reallocate the non-escaping objects and restore their fields.
1529   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1530   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1531 
1532   if (objects == NULL) {
1533     // no objects to materialize
1534     return;
1535   }
1536 
1537   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1538   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1539 
1540   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1541     compiledVFrame* cvf = virtualFrames->at(frame_index);
1542 
1543     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1544     StackValueCollection* locals = cvf->locals();
1545     if (locals != NULL) {
1546       for (int i2 = 0; i2 < locals->size(); i2++) {
1547         StackValue* var = locals->at(i2);
1548         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1549           jvalue val;
1550           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1551           cvf->update_local(T_OBJECT, i2, val);
1552         }
1553       }
1554     }
1555 
1556     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1557     StackValueCollection* expressions = cvf->expressions();
1558     if (expressions != NULL) {

1831   return JVMCIENV->get_jobject(result);
1832 C2V_END
1833 
1834 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, jobject holder))
1835   if (holder == NULL) {
1836     JVMCI_THROW_0(NullPointerException);
1837   }
1838   Klass* klass = JVMCIENV->asKlass(holder);
1839   if (!klass->is_instance_klass()) {
1840     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1841     return JVMCIENV->get_jobjectArray(methods);
1842   }
1843 
1844   InstanceKlass* iklass = InstanceKlass::cast(klass);
1845   // Ensure class is linked
1846   iklass->link_class(CHECK_NULL);
1847 
1848   GrowableArray<Method*> constructors_array;
1849   for (int i = 0; i < iklass->methods()->length(); i++) {
1850     Method* m = iklass->methods()->at(i);
1851     if (m->is_initializer() && !m->is_static()) {
1852       constructors_array.append(m);
1853     }
1854   }
1855   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1856   for (int i = 0; i < constructors_array.length(); i++) {
1857     methodHandle ctor(THREAD, constructors_array.at(i));
1858     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1859     JVMCIENV->put_object_at(methods, i, method);
1860   }
1861   return JVMCIENV->get_jobjectArray(methods);
1862 C2V_END
1863 
1864 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, jobject holder))
1865   if (holder == NULL) {
1866     JVMCI_THROW_0(NullPointerException);
1867   }
1868   Klass* klass = JVMCIENV->asKlass(holder);
1869   if (!klass->is_instance_klass()) {
1870     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1871     return JVMCIENV->get_jobjectArray(methods);
1872   }
1873 
1874   InstanceKlass* iklass = InstanceKlass::cast(klass);
1875   // Ensure class is linked
1876   iklass->link_class(CHECK_NULL);
1877 
1878   GrowableArray<Method*> methods_array;
1879   for (int i = 0; i < iklass->methods()->length(); i++) {
1880     Method* m = iklass->methods()->at(i);
1881     if (!m->is_initializer() && !m->is_overpass()) {
1882       methods_array.append(m);
1883     }
1884   }
1885   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1886   for (int i = 0; i < methods_array.length(); i++) {
1887     methodHandle mh(THREAD, methods_array.at(i));
1888     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1889     JVMCIENV->put_object_at(methods, i, method);
1890   }
1891   return JVMCIENV->get_jobjectArray(methods);
1892 C2V_END
1893 
1894 C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, jobject expected_type, long displacement, jboolean is_volatile, jobject kind_object))
1895   if (object == NULL || kind_object == NULL) {
1896     JVMCI_THROW_0(NullPointerException);
1897   }
1898 
1899   JVMCIObject kind = JVMCIENV->wrap(kind_object);
1900   BasicType basic_type = JVMCIENV->kindToBasicType(kind, JVMCI_CHECK_NULL);
1901 

2484   JVMCIENV->get_nmethod(code, locker);
2485 }
2486 
2487 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2488   JVMCIObject code = JVMCIENV->wrap(code_handle);
2489   nmethodLocker locker;
2490   CodeBlob* cb = JVMCIENV->get_code_blob(code, locker);
2491   if (cb == NULL) {
2492     return NULL;
2493   }
2494   int code_size = cb->code_size();
2495   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2496   JVMCIENV->copy_bytes_from((jbyte*) cb->code_begin(), result, 0, code_size);
2497   return JVMCIENV->get_jbyteArray(result);
2498 }
2499 
2500 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, jobject jvmci_method))
2501   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2502   methodHandle m(THREAD, JVMCIENV->asMethod(jvmci_method));
2503   oop executable;
2504   if (m->is_initializer()) {
2505     if (m->is_static_initializer()) {
2506       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2507           "Cannot create java.lang.reflect.Method for class initializer");
2508     }

2509     executable = Reflection::new_constructor(m, CHECK_NULL);
2510   } else {
2511     executable = Reflection::new_method(m, false, CHECK_NULL);
2512   }
2513   return JNIHandles::make_local(THREAD, executable);
2514 }
2515 
2516 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, jobject jvmci_type, jint index))
2517   requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2518   Klass* klass = JVMCIENV->asKlass(jvmci_type);
2519   if (!klass->is_instance_klass()) {
2520     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2521         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2522   }
2523   InstanceKlass* iklass = InstanceKlass::cast(klass);
2524   Array<u2>* fields = iklass->fields();
2525   if (index < 0 ||index > fields->length()) {
2526     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2527         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2528   }

1286         if (vf->is_compiled_frame()) {
1287           // compiled method frame
1288           compiledVFrame* cvf = compiledVFrame::cast(vf);
1289 
1290           ScopeDesc* scope = cvf->scope();
1291           // native wrappers do not have a scope
1292           if (scope != NULL && scope->objects() != NULL) {
1293             prev_cvf = cvf;
1294 
1295             GrowableArray<ScopeValue*>* objects = NULL;
1296             if (!realloc_called) {
1297               objects = scope->objects();
1298             } else {
1299               // some object might already have been re-allocated, only reallocate the non-allocated ones
1300               objects = get_unallocated_objects_or_null(scope->objects());
1301             }
1302 
1303             if (objects != NULL) {
1304               RegisterMap reg_map(vf->register_map());
1305               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1306               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false, CHECK_NULL);
1307               realloc_called = true;
1308             }
1309 
1310             GrowableArray<ScopeValue*>* local_values = scope->locals();
1311             for (int i = 0; i < local_values->length(); i++) {
1312               ScopeValue* value = local_values->at(i);
1313               if (value->is_object()) {
1314                 if (localIsVirtual_h.is_null()) {
1315                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1316                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1317                 }
1318                 localIsVirtual_h->bool_at_put(i, true);
1319               }
1320             }
1321           }
1322 
1323           locals = cvf->locals();
1324           frame_number = cvf->vframe_id();
1325         } else {
1326           // interpreted method frame

1518       break;
1519     }
1520     vf = vf->sender();
1521   }
1522 
1523   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1524   if (last_frame_number >= virtualFrames->length()) {
1525     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1526   }
1527 
1528   // Reallocate the non-escaping objects and restore their fields.
1529   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1530   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1531 
1532   if (objects == NULL) {
1533     // no objects to materialize
1534     return;
1535   }
1536 
1537   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1538   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1539 
1540   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1541     compiledVFrame* cvf = virtualFrames->at(frame_index);
1542 
1543     GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1544     StackValueCollection* locals = cvf->locals();
1545     if (locals != NULL) {
1546       for (int i2 = 0; i2 < locals->size(); i2++) {
1547         StackValue* var = locals->at(i2);
1548         if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1549           jvalue val;
1550           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1551           cvf->update_local(T_OBJECT, i2, val);
1552         }
1553       }
1554     }
1555 
1556     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1557     StackValueCollection* expressions = cvf->expressions();
1558     if (expressions != NULL) {

1831   return JVMCIENV->get_jobject(result);
1832 C2V_END
1833 
1834 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, jobject holder))
1835   if (holder == NULL) {
1836     JVMCI_THROW_0(NullPointerException);
1837   }
1838   Klass* klass = JVMCIENV->asKlass(holder);
1839   if (!klass->is_instance_klass()) {
1840     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1841     return JVMCIENV->get_jobjectArray(methods);
1842   }
1843 
1844   InstanceKlass* iklass = InstanceKlass::cast(klass);
1845   // Ensure class is linked
1846   iklass->link_class(CHECK_NULL);
1847 
1848   GrowableArray<Method*> constructors_array;
1849   for (int i = 0; i < iklass->methods()->length(); i++) {
1850     Method* m = iklass->methods()->at(i);
1851     if (m->is_object_constructor()) {
1852       constructors_array.append(m);
1853     }
1854   }
1855   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1856   for (int i = 0; i < constructors_array.length(); i++) {
1857     methodHandle ctor(THREAD, constructors_array.at(i));
1858     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1859     JVMCIENV->put_object_at(methods, i, method);
1860   }
1861   return JVMCIENV->get_jobjectArray(methods);
1862 C2V_END
1863 
1864 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, jobject holder))
1865   if (holder == NULL) {
1866     JVMCI_THROW_0(NullPointerException);
1867   }
1868   Klass* klass = JVMCIENV->asKlass(holder);
1869   if (!klass->is_instance_klass()) {
1870     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1871     return JVMCIENV->get_jobjectArray(methods);
1872   }
1873 
1874   InstanceKlass* iklass = InstanceKlass::cast(klass);
1875   // Ensure class is linked
1876   iklass->link_class(CHECK_NULL);
1877 
1878   GrowableArray<Method*> methods_array;
1879   for (int i = 0; i < iklass->methods()->length(); i++) {
1880     Method* m = iklass->methods()->at(i);
1881     if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
1882       methods_array.append(m);
1883     }
1884   }
1885   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1886   for (int i = 0; i < methods_array.length(); i++) {
1887     methodHandle mh(THREAD, methods_array.at(i));
1888     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1889     JVMCIENV->put_object_at(methods, i, method);
1890   }
1891   return JVMCIENV->get_jobjectArray(methods);
1892 C2V_END
1893 
1894 C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, jobject expected_type, long displacement, jboolean is_volatile, jobject kind_object))
1895   if (object == NULL || kind_object == NULL) {
1896     JVMCI_THROW_0(NullPointerException);
1897   }
1898 
1899   JVMCIObject kind = JVMCIENV->wrap(kind_object);
1900   BasicType basic_type = JVMCIENV->kindToBasicType(kind, JVMCI_CHECK_NULL);
1901 

2484   JVMCIENV->get_nmethod(code, locker);
2485 }
2486 
2487 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2488   JVMCIObject code = JVMCIENV->wrap(code_handle);
2489   nmethodLocker locker;
2490   CodeBlob* cb = JVMCIENV->get_code_blob(code, locker);
2491   if (cb == NULL) {
2492     return NULL;
2493   }
2494   int code_size = cb->code_size();
2495   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2496   JVMCIENV->copy_bytes_from((jbyte*) cb->code_begin(), result, 0, code_size);
2497   return JVMCIENV->get_jbyteArray(result);
2498 }
2499 
2500 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, jobject jvmci_method))
2501   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2502   methodHandle m(THREAD, JVMCIENV->asMethod(jvmci_method));
2503   oop executable;
2504   if (m->is_class_initializer()) {

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