< prev index next >

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Print this page

 115                       JavaCallArguments* jca,
 116                       arrayOop args,
 117                       bool is_static)
 118     : SignatureIterator(signature)
 119   {
 120     this->_return_type = T_ILLEGAL;
 121     _jca = jca;
 122     _index = 0;
 123     _args = args;
 124     if (!is_static) {
 125       _jca->push_oop(next_arg(T_OBJECT));
 126     }
 127     do_parameters_on(this);
 128     assert(_index == args->length(), "arg count mismatch with signature");
 129   }
 130 
 131  private:
 132   friend class SignatureIterator;  // so do_parameters_on can call do_type
 133   void do_type(BasicType type) {
 134     if (is_reference_type(type)) {
 135       _jca->push_oop(next_arg(T_OBJECT));
 136       return;
 137     }
 138     Handle arg = next_arg(type);
 139     int box_offset = java_lang_boxing_object::value_offset(type);
 140     switch (type) {
 141     case T_BOOLEAN:     _jca->push_int(arg->bool_field(box_offset));    break;
 142     case T_CHAR:        _jca->push_int(arg->char_field(box_offset));    break;
 143     case T_SHORT:       _jca->push_int(arg->short_field(box_offset));   break;
 144     case T_BYTE:        _jca->push_int(arg->byte_field(box_offset));    break;
 145     case T_INT:         _jca->push_int(arg->int_field(box_offset));     break;
 146     case T_LONG:        _jca->push_long(arg->long_field(box_offset));   break;
 147     case T_FLOAT:       _jca->push_float(arg->float_field(box_offset));    break;
 148     case T_DOUBLE:      _jca->push_double(arg->double_field(box_offset));  break;
 149     default:            ShouldNotReachHere();
 150     }
 151   }
 152 };
 153 
 154 Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
 155   assert(_index < _args->length(), "out of bounds");

1474         if (vf->is_compiled_frame()) {
1475           // compiled method frame
1476           compiledVFrame* cvf = compiledVFrame::cast(vf);
1477 
1478           ScopeDesc* scope = cvf->scope();
1479           // native wrappers do not have a scope
1480           if (scope != nullptr && scope->objects() != nullptr) {
1481             prev_cvf = cvf;
1482 
1483             GrowableArray<ScopeValue*>* objects = nullptr;
1484             if (!realloc_called) {
1485               objects = scope->objects();
1486             } else {
1487               // some object might already have been re-allocated, only reallocate the non-allocated ones
1488               objects = get_unallocated_objects_or_null(scope->objects());
1489             }
1490 
1491             if (objects != nullptr) {
1492               RegisterMap reg_map(vf->register_map());
1493               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1494               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1495               realloc_called = true;
1496             }
1497 
1498             GrowableArray<ScopeValue*>* local_values = scope->locals();
1499             for (int i = 0; i < local_values->length(); i++) {
1500               ScopeValue* value = local_values->at(i);
1501               if (value->is_object()) {
1502                 if (localIsVirtual_h.is_null()) {
1503                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1504                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1505                 }
1506                 localIsVirtual_h->bool_at_put(i, true);
1507               }
1508             }
1509           }
1510 
1511           locals = cvf->locals();
1512           frame_number = cvf->vframe_id();
1513         } else {
1514           // interpreted method frame

1713       break;
1714     }
1715     vf = vf->sender();
1716   }
1717 
1718   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1719   if (last_frame_number >= virtualFrames->length()) {
1720     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1721   }
1722 
1723   // Reallocate the non-escaping objects and restore their fields.
1724   assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1725   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1726 
1727   if (objects == nullptr) {
1728     // no objects to materialize
1729     return;
1730   }
1731 
1732   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1733   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1734 
1735   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1736     compiledVFrame* cvf = virtualFrames->at(frame_index);
1737 
1738     GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1739     StackValueCollection* locals = cvf->locals();
1740     if (locals != nullptr) {
1741       for (int i2 = 0; i2 < locals->size(); i2++) {
1742         StackValue* var = locals->at(i2);
1743         if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1744           jvalue val;
1745           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1746           cvf->update_local(T_OBJECT, i2, val);
1747         }
1748       }
1749     }
1750 
1751     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1752     StackValueCollection* expressions = cvf->expressions();
1753     if (expressions != nullptr) {

2035                          box_signature, &jargs, CHECK_NULL);
2036   oop hotspot_box = box_result.get_oop();
2037   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2038   return JVMCIENV->get_jobject(result);
2039 C2V_END
2040 
2041 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2042   Klass* klass = UNPACK_PAIR(Klass, klass);
2043   if (klass == nullptr) {
2044     JVMCI_THROW_0(NullPointerException);
2045   }
2046   if (!klass->is_instance_klass()) {
2047     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2048     return JVMCIENV->get_jobjectArray(methods);
2049   }
2050 
2051   InstanceKlass* iklass = InstanceKlass::cast(klass);
2052   GrowableArray<Method*> constructors_array;
2053   for (int i = 0; i < iklass->methods()->length(); i++) {
2054     Method* m = iklass->methods()->at(i);
2055     if (m->is_initializer() && !m->is_static()) {
2056       constructors_array.append(m);
2057     }
2058   }
2059   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2060   for (int i = 0; i < constructors_array.length(); i++) {
2061     methodHandle ctor(THREAD, constructors_array.at(i));
2062     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2063     JVMCIENV->put_object_at(methods, i, method);
2064   }
2065   return JVMCIENV->get_jobjectArray(methods);
2066 C2V_END
2067 
2068 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2069   Klass* klass = UNPACK_PAIR(Klass, klass);
2070   if (klass == nullptr) {
2071     JVMCI_THROW_0(NullPointerException);
2072   }
2073   if (!klass->is_instance_klass()) {
2074     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2075     return JVMCIENV->get_jobjectArray(methods);
2076   }
2077 
2078   InstanceKlass* iklass = InstanceKlass::cast(klass);
2079   GrowableArray<Method*> methods_array;
2080   for (int i = 0; i < iklass->methods()->length(); i++) {
2081     Method* m = iklass->methods()->at(i);
2082     if (!m->is_initializer() && !m->is_overpass()) {
2083       methods_array.append(m);
2084     }
2085   }
2086   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2087   for (int i = 0; i < methods_array.length(); i++) {
2088     methodHandle mh(THREAD, methods_array.at(i));
2089     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2090     JVMCIENV->put_object_at(methods, i, method);
2091   }
2092   return JVMCIENV->get_jobjectArray(methods);
2093 C2V_END
2094 
2095 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2096   Klass* klass = UNPACK_PAIR(Klass, klass);
2097   if (klass == nullptr) {
2098     JVMCI_THROW_0(NullPointerException);
2099   }
2100   if (!klass->is_instance_klass()) {
2101     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2102   }

2775 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2776   JVMCIObject code = JVMCIENV->wrap(code_handle);
2777   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2778   if (cb == nullptr) {
2779     return nullptr;
2780   }
2781   // Make a resource copy of code before the allocation causes a safepoint
2782   int code_size = cb->code_size();
2783   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2784   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2785 
2786   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2787   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2788   return JVMCIENV->get_jbyteArray(result);
2789 }
2790 
2791 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2792   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2793   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2794   oop executable;
2795   if (m->is_initializer()) {
2796     if (m->is_static_initializer()) {
2797       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2798           "Cannot create java.lang.reflect.Method for class initializer");
2799     }

2800     executable = Reflection::new_constructor(m, CHECK_NULL);
2801   } else {
2802     executable = Reflection::new_method(m, false, CHECK_NULL);
2803   }
2804   return JNIHandles::make_local(THREAD, executable);
2805 }
2806 
2807 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2808   if (!klass->is_instance_klass()) {
2809     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2810         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2811   }
2812   InstanceKlass* iklass = InstanceKlass::cast(klass);
2813   if (index < 0 || index > iklass->total_fields_count()) {
2814     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2815         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2816   }
2817   return iklass;
2818 }
2819 

 115                       JavaCallArguments* jca,
 116                       arrayOop args,
 117                       bool is_static)
 118     : SignatureIterator(signature)
 119   {
 120     this->_return_type = T_ILLEGAL;
 121     _jca = jca;
 122     _index = 0;
 123     _args = args;
 124     if (!is_static) {
 125       _jca->push_oop(next_arg(T_OBJECT));
 126     }
 127     do_parameters_on(this);
 128     assert(_index == args->length(), "arg count mismatch with signature");
 129   }
 130 
 131  private:
 132   friend class SignatureIterator;  // so do_parameters_on can call do_type
 133   void do_type(BasicType type) {
 134     if (is_reference_type(type)) {
 135       (type == T_PRIMITIVE_OBJECT) ? _jca->push_oop(next_arg(T_PRIMITIVE_OBJECT)) : _jca->push_oop(next_arg(T_OBJECT));
 136       return;
 137     }
 138     Handle arg = next_arg(type);
 139     int box_offset = java_lang_boxing_object::value_offset(type);
 140     switch (type) {
 141     case T_BOOLEAN:     _jca->push_int(arg->bool_field(box_offset));    break;
 142     case T_CHAR:        _jca->push_int(arg->char_field(box_offset));    break;
 143     case T_SHORT:       _jca->push_int(arg->short_field(box_offset));   break;
 144     case T_BYTE:        _jca->push_int(arg->byte_field(box_offset));    break;
 145     case T_INT:         _jca->push_int(arg->int_field(box_offset));     break;
 146     case T_LONG:        _jca->push_long(arg->long_field(box_offset));   break;
 147     case T_FLOAT:       _jca->push_float(arg->float_field(box_offset));    break;
 148     case T_DOUBLE:      _jca->push_double(arg->double_field(box_offset));  break;
 149     default:            ShouldNotReachHere();
 150     }
 151   }
 152 };
 153 
 154 Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
 155   assert(_index < _args->length(), "out of bounds");

1474         if (vf->is_compiled_frame()) {
1475           // compiled method frame
1476           compiledVFrame* cvf = compiledVFrame::cast(vf);
1477 
1478           ScopeDesc* scope = cvf->scope();
1479           // native wrappers do not have a scope
1480           if (scope != nullptr && scope->objects() != nullptr) {
1481             prev_cvf = cvf;
1482 
1483             GrowableArray<ScopeValue*>* objects = nullptr;
1484             if (!realloc_called) {
1485               objects = scope->objects();
1486             } else {
1487               // some object might already have been re-allocated, only reallocate the non-allocated ones
1488               objects = get_unallocated_objects_or_null(scope->objects());
1489             }
1490 
1491             if (objects != nullptr) {
1492               RegisterMap reg_map(vf->register_map());
1493               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1494               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false, CHECK_NULL);
1495               realloc_called = true;
1496             }
1497 
1498             GrowableArray<ScopeValue*>* local_values = scope->locals();
1499             for (int i = 0; i < local_values->length(); i++) {
1500               ScopeValue* value = local_values->at(i);
1501               if (value->is_object()) {
1502                 if (localIsVirtual_h.is_null()) {
1503                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1504                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1505                 }
1506                 localIsVirtual_h->bool_at_put(i, true);
1507               }
1508             }
1509           }
1510 
1511           locals = cvf->locals();
1512           frame_number = cvf->vframe_id();
1513         } else {
1514           // interpreted method frame

1713       break;
1714     }
1715     vf = vf->sender();
1716   }
1717 
1718   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1719   if (last_frame_number >= virtualFrames->length()) {
1720     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1721   }
1722 
1723   // Reallocate the non-escaping objects and restore their fields.
1724   assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1725   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1726 
1727   if (objects == nullptr) {
1728     // no objects to materialize
1729     return;
1730   }
1731 
1732   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1733   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1734 
1735   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1736     compiledVFrame* cvf = virtualFrames->at(frame_index);
1737 
1738     GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1739     StackValueCollection* locals = cvf->locals();
1740     if (locals != nullptr) {
1741       for (int i2 = 0; i2 < locals->size(); i2++) {
1742         StackValue* var = locals->at(i2);
1743         if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1744           jvalue val;
1745           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1746           cvf->update_local(T_OBJECT, i2, val);
1747         }
1748       }
1749     }
1750 
1751     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1752     StackValueCollection* expressions = cvf->expressions();
1753     if (expressions != nullptr) {

2035                          box_signature, &jargs, CHECK_NULL);
2036   oop hotspot_box = box_result.get_oop();
2037   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2038   return JVMCIENV->get_jobject(result);
2039 C2V_END
2040 
2041 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2042   Klass* klass = UNPACK_PAIR(Klass, klass);
2043   if (klass == nullptr) {
2044     JVMCI_THROW_0(NullPointerException);
2045   }
2046   if (!klass->is_instance_klass()) {
2047     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2048     return JVMCIENV->get_jobjectArray(methods);
2049   }
2050 
2051   InstanceKlass* iklass = InstanceKlass::cast(klass);
2052   GrowableArray<Method*> constructors_array;
2053   for (int i = 0; i < iklass->methods()->length(); i++) {
2054     Method* m = iklass->methods()->at(i);
2055     if (m->is_object_constructor()) {
2056       constructors_array.append(m);
2057     }
2058   }
2059   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2060   for (int i = 0; i < constructors_array.length(); i++) {
2061     methodHandle ctor(THREAD, constructors_array.at(i));
2062     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2063     JVMCIENV->put_object_at(methods, i, method);
2064   }
2065   return JVMCIENV->get_jobjectArray(methods);
2066 C2V_END
2067 
2068 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2069   Klass* klass = UNPACK_PAIR(Klass, klass);
2070   if (klass == nullptr) {
2071     JVMCI_THROW_0(NullPointerException);
2072   }
2073   if (!klass->is_instance_klass()) {
2074     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2075     return JVMCIENV->get_jobjectArray(methods);
2076   }
2077 
2078   InstanceKlass* iklass = InstanceKlass::cast(klass);
2079   GrowableArray<Method*> methods_array;
2080   for (int i = 0; i < iklass->methods()->length(); i++) {
2081     Method* m = iklass->methods()->at(i);
2082     if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
2083       methods_array.append(m);
2084     }
2085   }
2086   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2087   for (int i = 0; i < methods_array.length(); i++) {
2088     methodHandle mh(THREAD, methods_array.at(i));
2089     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2090     JVMCIENV->put_object_at(methods, i, method);
2091   }
2092   return JVMCIENV->get_jobjectArray(methods);
2093 C2V_END
2094 
2095 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2096   Klass* klass = UNPACK_PAIR(Klass, klass);
2097   if (klass == nullptr) {
2098     JVMCI_THROW_0(NullPointerException);
2099   }
2100   if (!klass->is_instance_klass()) {
2101     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2102   }

2775 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2776   JVMCIObject code = JVMCIENV->wrap(code_handle);
2777   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2778   if (cb == nullptr) {
2779     return nullptr;
2780   }
2781   // Make a resource copy of code before the allocation causes a safepoint
2782   int code_size = cb->code_size();
2783   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2784   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2785 
2786   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2787   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2788   return JVMCIENV->get_jbyteArray(result);
2789 }
2790 
2791 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2792   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2793   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2794   oop executable;
2795   if (m->is_class_initializer()) {

2796       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2797           "Cannot create java.lang.reflect.Method for class initializer");
2798   }
2799   else if (m->is_object_constructor() || m->is_static_vnew_factory()) {
2800     executable = Reflection::new_constructor(m, CHECK_NULL);
2801   } else {
2802     executable = Reflection::new_method(m, false, CHECK_NULL);
2803   }
2804   return JNIHandles::make_local(THREAD, executable);
2805 }
2806 
2807 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2808   if (!klass->is_instance_klass()) {
2809     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2810         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2811   }
2812   InstanceKlass* iklass = InstanceKlass::cast(klass);
2813   if (index < 0 || index > iklass->total_fields_count()) {
2814     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2815         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2816   }
2817   return iklass;
2818 }
2819 
< prev index next >