< prev index next >

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Print this page

1345         if (vf->is_compiled_frame()) {
1346           // compiled method frame
1347           compiledVFrame* cvf = compiledVFrame::cast(vf);
1348 
1349           ScopeDesc* scope = cvf->scope();
1350           // native wrappers do not have a scope
1351           if (scope != NULL && scope->objects() != NULL) {
1352             prev_cvf = cvf;
1353 
1354             GrowableArray<ScopeValue*>* objects = NULL;
1355             if (!realloc_called) {
1356               objects = scope->objects();
1357             } else {
1358               // some object might already have been re-allocated, only reallocate the non-allocated ones
1359               objects = get_unallocated_objects_or_null(scope->objects());
1360             }
1361 
1362             if (objects != NULL) {
1363               RegisterMap reg_map(vf->register_map());
1364               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1365               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1366               realloc_called = true;
1367             }
1368 
1369             GrowableArray<ScopeValue*>* local_values = scope->locals();
1370             for (int i = 0; i < local_values->length(); i++) {
1371               ScopeValue* value = local_values->at(i);
1372               if (value->is_object()) {
1373                 if (localIsVirtual_h.is_null()) {
1374                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1375                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1376                 }
1377                 localIsVirtual_h->bool_at_put(i, true);
1378               }
1379             }
1380           }
1381 
1382           locals = cvf->locals();
1383           frame_number = cvf->vframe_id();
1384         } else {
1385           // interpreted method frame

1577       break;
1578     }
1579     vf = vf->sender();
1580   }
1581 
1582   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1583   if (last_frame_number >= virtualFrames->length()) {
1584     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1585   }
1586 
1587   // Reallocate the non-escaping objects and restore their fields.
1588   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1589   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1590 
1591   if (objects == NULL) {
1592     // no objects to materialize
1593     return;
1594   }
1595 
1596   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1597   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1598 
1599   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1600     compiledVFrame* cvf = virtualFrames->at(frame_index);
1601 
1602     GrowableArray<ScopeValue*>* extentLocals = cvf->scope()->locals();
1603     StackValueCollection* locals = cvf->locals();
1604     if (locals != NULL) {
1605       for (int i2 = 0; i2 < locals->size(); i2++) {
1606         StackValue* var = locals->at(i2);
1607         if (var->type() == T_OBJECT && extentLocals->at(i2)->is_object()) {
1608           jvalue val;
1609           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1610           cvf->update_local(T_OBJECT, i2, val);
1611         }
1612       }
1613     }
1614 
1615     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1616     StackValueCollection* expressions = cvf->expressions();
1617     if (expressions != NULL) {

1880   return JVMCIENV->get_jobject(result);
1881 C2V_END
1882 
1883 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
1884   Klass* klass = UNPACK_PAIR(Klass, klass);
1885   if (klass == nullptr) {
1886     JVMCI_THROW_0(NullPointerException);
1887   }
1888   if (!klass->is_instance_klass()) {
1889     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1890     return JVMCIENV->get_jobjectArray(methods);
1891   }
1892 
1893   InstanceKlass* iklass = InstanceKlass::cast(klass);
1894   // Ensure class is linked
1895   iklass->link_class(CHECK_NULL);
1896 
1897   GrowableArray<Method*> constructors_array;
1898   for (int i = 0; i < iklass->methods()->length(); i++) {
1899     Method* m = iklass->methods()->at(i);
1900     if (m->is_initializer() && !m->is_static()) {
1901       constructors_array.append(m);
1902     }
1903   }
1904   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1905   for (int i = 0; i < constructors_array.length(); i++) {
1906     methodHandle ctor(THREAD, constructors_array.at(i));
1907     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1908     JVMCIENV->put_object_at(methods, i, method);
1909   }
1910   return JVMCIENV->get_jobjectArray(methods);
1911 C2V_END
1912 
1913 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
1914   Klass* klass = UNPACK_PAIR(Klass, klass);
1915   if (klass == nullptr) {
1916     JVMCI_THROW_0(NullPointerException);
1917   }
1918   if (!klass->is_instance_klass()) {
1919     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1920     return JVMCIENV->get_jobjectArray(methods);
1921   }
1922 
1923   InstanceKlass* iklass = InstanceKlass::cast(klass);
1924   // Ensure class is linked
1925   iklass->link_class(CHECK_NULL);
1926 
1927   GrowableArray<Method*> methods_array;
1928   for (int i = 0; i < iklass->methods()->length(); i++) {
1929     Method* m = iklass->methods()->at(i);
1930     if (!m->is_initializer() && !m->is_overpass()) {
1931       methods_array.append(m);
1932     }
1933   }
1934   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1935   for (int i = 0; i < methods_array.length(); i++) {
1936     methodHandle mh(THREAD, methods_array.at(i));
1937     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1938     JVMCIENV->put_object_at(methods, i, method);
1939   }
1940   return JVMCIENV->get_jobjectArray(methods);
1941 C2V_END
1942 
1943 static jobject read_field_value(Handle obj, long displacement, jchar type_char, bool is_static, Thread* THREAD, JVMCIEnv* JVMCIENV) {
1944 
1945   BasicType basic_type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_NULL);
1946   int basic_type_elemsize = type2aelembytes(basic_type);
1947   if (displacement < 0 || ((size_t) displacement + basic_type_elemsize > HeapWordSize * obj->size())) {
1948     // Reading outside of the object bounds
1949     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading outside object bounds");
1950   }

2590 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2591   JVMCIObject code = JVMCIENV->wrap(code_handle);
2592   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2593   if (cb == NULL) {
2594     return NULL;
2595   }
2596   // Make a resource copy of code before the allocation causes a safepoint
2597   int code_size = cb->code_size();
2598   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2599   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2600 
2601   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2602   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2603   return JVMCIENV->get_jbyteArray(result);
2604 }
2605 
2606 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2607   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2608   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2609   oop executable;
2610   if (m->is_initializer()) {
2611     if (m->is_static_initializer()) {
2612       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2613           "Cannot create java.lang.reflect.Method for class initializer");
2614     }

2615     executable = Reflection::new_constructor(m, CHECK_NULL);
2616   } else {
2617     executable = Reflection::new_method(m, false, CHECK_NULL);
2618   }
2619   return JNIHandles::make_local(THREAD, executable);
2620 }
2621 
2622 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))
2623   requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2624   Klass* klass = UNPACK_PAIR(Klass, klass);
2625   if (!klass->is_instance_klass()) {
2626     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2627         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2628   }
2629   InstanceKlass* iklass = InstanceKlass::cast(klass);
2630   Array<u2>* fields = iklass->fields();
2631   if (index < 0 ||index > fields->length()) {
2632     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2633         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2634   }

1345         if (vf->is_compiled_frame()) {
1346           // compiled method frame
1347           compiledVFrame* cvf = compiledVFrame::cast(vf);
1348 
1349           ScopeDesc* scope = cvf->scope();
1350           // native wrappers do not have a scope
1351           if (scope != NULL && scope->objects() != NULL) {
1352             prev_cvf = cvf;
1353 
1354             GrowableArray<ScopeValue*>* objects = NULL;
1355             if (!realloc_called) {
1356               objects = scope->objects();
1357             } else {
1358               // some object might already have been re-allocated, only reallocate the non-allocated ones
1359               objects = get_unallocated_objects_or_null(scope->objects());
1360             }
1361 
1362             if (objects != NULL) {
1363               RegisterMap reg_map(vf->register_map());
1364               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1365               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false, CHECK_NULL);
1366               realloc_called = true;
1367             }
1368 
1369             GrowableArray<ScopeValue*>* local_values = scope->locals();
1370             for (int i = 0; i < local_values->length(); i++) {
1371               ScopeValue* value = local_values->at(i);
1372               if (value->is_object()) {
1373                 if (localIsVirtual_h.is_null()) {
1374                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1375                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1376                 }
1377                 localIsVirtual_h->bool_at_put(i, true);
1378               }
1379             }
1380           }
1381 
1382           locals = cvf->locals();
1383           frame_number = cvf->vframe_id();
1384         } else {
1385           // interpreted method frame

1577       break;
1578     }
1579     vf = vf->sender();
1580   }
1581 
1582   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1583   if (last_frame_number >= virtualFrames->length()) {
1584     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1585   }
1586 
1587   // Reallocate the non-escaping objects and restore their fields.
1588   assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1589   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1590 
1591   if (objects == NULL) {
1592     // no objects to materialize
1593     return;
1594   }
1595 
1596   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1597   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1598 
1599   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1600     compiledVFrame* cvf = virtualFrames->at(frame_index);
1601 
1602     GrowableArray<ScopeValue*>* extentLocals = cvf->scope()->locals();
1603     StackValueCollection* locals = cvf->locals();
1604     if (locals != NULL) {
1605       for (int i2 = 0; i2 < locals->size(); i2++) {
1606         StackValue* var = locals->at(i2);
1607         if (var->type() == T_OBJECT && extentLocals->at(i2)->is_object()) {
1608           jvalue val;
1609           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1610           cvf->update_local(T_OBJECT, i2, val);
1611         }
1612       }
1613     }
1614 
1615     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1616     StackValueCollection* expressions = cvf->expressions();
1617     if (expressions != NULL) {

1880   return JVMCIENV->get_jobject(result);
1881 C2V_END
1882 
1883 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
1884   Klass* klass = UNPACK_PAIR(Klass, klass);
1885   if (klass == nullptr) {
1886     JVMCI_THROW_0(NullPointerException);
1887   }
1888   if (!klass->is_instance_klass()) {
1889     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1890     return JVMCIENV->get_jobjectArray(methods);
1891   }
1892 
1893   InstanceKlass* iklass = InstanceKlass::cast(klass);
1894   // Ensure class is linked
1895   iklass->link_class(CHECK_NULL);
1896 
1897   GrowableArray<Method*> constructors_array;
1898   for (int i = 0; i < iklass->methods()->length(); i++) {
1899     Method* m = iklass->methods()->at(i);
1900     if (m->is_object_constructor()) {
1901       constructors_array.append(m);
1902     }
1903   }
1904   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1905   for (int i = 0; i < constructors_array.length(); i++) {
1906     methodHandle ctor(THREAD, constructors_array.at(i));
1907     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
1908     JVMCIENV->put_object_at(methods, i, method);
1909   }
1910   return JVMCIENV->get_jobjectArray(methods);
1911 C2V_END
1912 
1913 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
1914   Klass* klass = UNPACK_PAIR(Klass, klass);
1915   if (klass == nullptr) {
1916     JVMCI_THROW_0(NullPointerException);
1917   }
1918   if (!klass->is_instance_klass()) {
1919     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1920     return JVMCIENV->get_jobjectArray(methods);
1921   }
1922 
1923   InstanceKlass* iklass = InstanceKlass::cast(klass);
1924   // Ensure class is linked
1925   iklass->link_class(CHECK_NULL);
1926 
1927   GrowableArray<Method*> methods_array;
1928   for (int i = 0; i < iklass->methods()->length(); i++) {
1929     Method* m = iklass->methods()->at(i);
1930     if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
1931       methods_array.append(m);
1932     }
1933   }
1934   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1935   for (int i = 0; i < methods_array.length(); i++) {
1936     methodHandle mh(THREAD, methods_array.at(i));
1937     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
1938     JVMCIENV->put_object_at(methods, i, method);
1939   }
1940   return JVMCIENV->get_jobjectArray(methods);
1941 C2V_END
1942 
1943 static jobject read_field_value(Handle obj, long displacement, jchar type_char, bool is_static, Thread* THREAD, JVMCIEnv* JVMCIENV) {
1944 
1945   BasicType basic_type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_NULL);
1946   int basic_type_elemsize = type2aelembytes(basic_type);
1947   if (displacement < 0 || ((size_t) displacement + basic_type_elemsize > HeapWordSize * obj->size())) {
1948     // Reading outside of the object bounds
1949     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading outside object bounds");
1950   }

2590 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2591   JVMCIObject code = JVMCIENV->wrap(code_handle);
2592   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2593   if (cb == NULL) {
2594     return NULL;
2595   }
2596   // Make a resource copy of code before the allocation causes a safepoint
2597   int code_size = cb->code_size();
2598   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2599   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2600 
2601   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2602   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2603   return JVMCIENV->get_jbyteArray(result);
2604 }
2605 
2606 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2607   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2608   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2609   oop executable;
2610   if (m->is_class_initializer()) {

2611       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2612           "Cannot create java.lang.reflect.Method for class initializer");
2613   }
2614   else if (m->is_object_constructor() || m->is_static_vnew_factory()) {
2615     executable = Reflection::new_constructor(m, CHECK_NULL);
2616   } else {
2617     executable = Reflection::new_method(m, false, CHECK_NULL);
2618   }
2619   return JNIHandles::make_local(THREAD, executable);
2620 }
2621 
2622 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))
2623   requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2624   Klass* klass = UNPACK_PAIR(Klass, klass);
2625   if (!klass->is_instance_klass()) {
2626     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2627         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2628   }
2629   InstanceKlass* iklass = InstanceKlass::cast(klass);
2630   Array<u2>* fields = iklass->fields();
2631   if (index < 0 ||index > fields->length()) {
2632     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2633         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2634   }
< prev index next >