116 JavaCallArguments* jca,
117 arrayOop args,
118 bool is_static)
119 : SignatureIterator(signature)
120 {
121 this->_return_type = T_ILLEGAL;
122 _jca = jca;
123 _index = 0;
124 _args = args;
125 if (!is_static) {
126 _jca->push_oop(next_arg(T_OBJECT));
127 }
128 do_parameters_on(this);
129 assert(_index == args->length(), "arg count mismatch with signature");
130 }
131
132 private:
133 friend class SignatureIterator; // so do_parameters_on can call do_type
134 void do_type(BasicType type) {
135 if (is_reference_type(type)) {
136 _jca->push_oop(next_arg(T_OBJECT));
137 return;
138 }
139 Handle arg = next_arg(type);
140 int box_offset = java_lang_boxing_object::value_offset(type);
141 switch (type) {
142 case T_BOOLEAN: _jca->push_int(arg->bool_field(box_offset)); break;
143 case T_CHAR: _jca->push_int(arg->char_field(box_offset)); break;
144 case T_SHORT: _jca->push_int(arg->short_field(box_offset)); break;
145 case T_BYTE: _jca->push_int(arg->byte_field(box_offset)); break;
146 case T_INT: _jca->push_int(arg->int_field(box_offset)); break;
147 case T_LONG: _jca->push_long(arg->long_field(box_offset)); break;
148 case T_FLOAT: _jca->push_float(arg->float_field(box_offset)); break;
149 case T_DOUBLE: _jca->push_double(arg->double_field(box_offset)); break;
150 default: ShouldNotReachHere();
151 }
152 }
153 };
154
155 Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
156 assert(_index < _args->length(), "out of bounds");
1498 if (vf->is_compiled_frame()) {
1499 // compiled method frame
1500 compiledVFrame* cvf = compiledVFrame::cast(vf);
1501
1502 ScopeDesc* scope = cvf->scope();
1503 // native wrappers do not have a scope
1504 if (scope != nullptr && scope->objects() != nullptr) {
1505 prev_cvf = cvf;
1506
1507 GrowableArray<ScopeValue*>* objects = nullptr;
1508 if (!realloc_called) {
1509 objects = scope->objects();
1510 } else {
1511 // some object might already have been re-allocated, only reallocate the non-allocated ones
1512 objects = get_unallocated_objects_or_null(scope->objects());
1513 }
1514
1515 if (objects != nullptr) {
1516 RegisterMap reg_map(vf->register_map());
1517 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL);
1518 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false);
1519 realloc_called = true;
1520 }
1521
1522 GrowableArray<ScopeValue*>* local_values = scope->locals();
1523 for (int i = 0; i < local_values->length(); i++) {
1524 ScopeValue* value = local_values->at(i);
1525 assert(!value->is_object_merge(), "Should not be.");
1526 if (value->is_object()) {
1527 if (localIsVirtual_h.is_null()) {
1528 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1529 localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1530 }
1531 localIsVirtual_h->bool_at_put(i, true);
1532 }
1533 }
1534 }
1535
1536 locals = cvf->locals();
1537 frame_number = cvf->vframe_id();
1538 } else {
1748 break;
1749 }
1750 vf = vf->sender();
1751 }
1752
1753 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1754 if (last_frame_number >= virtualFrames->length()) {
1755 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1756 }
1757
1758 // Reallocate the non-escaping objects and restore their fields.
1759 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1760 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1761
1762 if (objects == nullptr) {
1763 // no objects to materialize
1764 return;
1765 }
1766
1767 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1768 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1769
1770 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1771 compiledVFrame* cvf = virtualFrames->at(frame_index);
1772
1773 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1774 StackValueCollection* locals = cvf->locals();
1775 if (locals != nullptr) {
1776 for (int i2 = 0; i2 < locals->size(); i2++) {
1777 StackValue* var = locals->at(i2);
1778 assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1779 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1780 jvalue val;
1781 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1782 cvf->update_local(T_OBJECT, i2, val);
1783 }
1784 }
1785 }
1786
1787 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1788 StackValueCollection* expressions = cvf->expressions();
2072 box_signature, &jargs, CHECK_NULL);
2073 oop hotspot_box = box_result.get_oop();
2074 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2075 return JVMCIENV->get_jobject(result);
2076 C2V_END
2077
2078 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2079 Klass* klass = UNPACK_PAIR(Klass, klass);
2080 if (klass == nullptr) {
2081 JVMCI_THROW_0(NullPointerException);
2082 }
2083 if (!klass->is_instance_klass()) {
2084 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2085 return JVMCIENV->get_jobjectArray(methods);
2086 }
2087
2088 InstanceKlass* iklass = InstanceKlass::cast(klass);
2089 GrowableArray<Method*> constructors_array;
2090 for (int i = 0; i < iklass->methods()->length(); i++) {
2091 Method* m = iklass->methods()->at(i);
2092 if (m->is_initializer() && !m->is_static()) {
2093 constructors_array.append(m);
2094 }
2095 }
2096 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2097 for (int i = 0; i < constructors_array.length(); i++) {
2098 methodHandle ctor(THREAD, constructors_array.at(i));
2099 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2100 JVMCIENV->put_object_at(methods, i, method);
2101 }
2102 return JVMCIENV->get_jobjectArray(methods);
2103 C2V_END
2104
2105 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2106 Klass* klass = UNPACK_PAIR(Klass, klass);
2107 if (klass == nullptr) {
2108 JVMCI_THROW_0(NullPointerException);
2109 }
2110 if (!klass->is_instance_klass()) {
2111 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2112 return JVMCIENV->get_jobjectArray(methods);
2113 }
2114
2115 InstanceKlass* iklass = InstanceKlass::cast(klass);
2116 GrowableArray<Method*> methods_array;
2117 for (int i = 0; i < iklass->methods()->length(); i++) {
2118 Method* m = iklass->methods()->at(i);
2119 if (!m->is_initializer() && !m->is_overpass()) {
2120 methods_array.append(m);
2121 }
2122 }
2123 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2124 for (int i = 0; i < methods_array.length(); i++) {
2125 methodHandle mh(THREAD, methods_array.at(i));
2126 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2127 JVMCIENV->put_object_at(methods, i, method);
2128 }
2129 return JVMCIENV->get_jobjectArray(methods);
2130 C2V_END
2131
2132 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2133 Klass* klass = UNPACK_PAIR(Klass, klass);
2134 if (klass == nullptr) {
2135 JVMCI_THROW_0(NullPointerException);
2136 }
2137 if (!klass->is_instance_klass()) {
2138 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2139 }
2801 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2802 JVMCIObject code = JVMCIENV->wrap(code_handle);
2803 CodeBlob* cb = JVMCIENV->get_code_blob(code);
2804 if (cb == nullptr) {
2805 return nullptr;
2806 }
2807 // Make a resource copy of code before the allocation causes a safepoint
2808 int code_size = cb->code_size();
2809 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2810 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2811
2812 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2813 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2814 return JVMCIENV->get_jbyteArray(result);
2815 }
2816
2817 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2818 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2819 methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2820 oop executable;
2821 if (m->is_initializer()) {
2822 if (m->is_static_initializer()) {
2823 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2824 "Cannot create java.lang.reflect.Method for class initializer");
2825 }
2826 executable = Reflection::new_constructor(m, CHECK_NULL);
2827 } else {
2828 executable = Reflection::new_method(m, false, CHECK_NULL);
2829 }
2830 return JNIHandles::make_local(THREAD, executable);
2831 }
2832
2833 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2834 if (!klass->is_instance_klass()) {
2835 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2836 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2837 }
2838 InstanceKlass* iklass = InstanceKlass::cast(klass);
2839 if (index < 0 || index > iklass->total_fields_count()) {
2840 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2841 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2842 }
2843 return iklass;
2844 }
2845
|
116 JavaCallArguments* jca,
117 arrayOop args,
118 bool is_static)
119 : SignatureIterator(signature)
120 {
121 this->_return_type = T_ILLEGAL;
122 _jca = jca;
123 _index = 0;
124 _args = args;
125 if (!is_static) {
126 _jca->push_oop(next_arg(T_OBJECT));
127 }
128 do_parameters_on(this);
129 assert(_index == args->length(), "arg count mismatch with signature");
130 }
131
132 private:
133 friend class SignatureIterator; // so do_parameters_on can call do_type
134 void do_type(BasicType type) {
135 if (is_reference_type(type)) {
136 (type == T_PRIMITIVE_OBJECT) ? _jca->push_oop(next_arg(T_PRIMITIVE_OBJECT)) : _jca->push_oop(next_arg(T_OBJECT));
137 return;
138 }
139 Handle arg = next_arg(type);
140 int box_offset = java_lang_boxing_object::value_offset(type);
141 switch (type) {
142 case T_BOOLEAN: _jca->push_int(arg->bool_field(box_offset)); break;
143 case T_CHAR: _jca->push_int(arg->char_field(box_offset)); break;
144 case T_SHORT: _jca->push_int(arg->short_field(box_offset)); break;
145 case T_BYTE: _jca->push_int(arg->byte_field(box_offset)); break;
146 case T_INT: _jca->push_int(arg->int_field(box_offset)); break;
147 case T_LONG: _jca->push_long(arg->long_field(box_offset)); break;
148 case T_FLOAT: _jca->push_float(arg->float_field(box_offset)); break;
149 case T_DOUBLE: _jca->push_double(arg->double_field(box_offset)); break;
150 default: ShouldNotReachHere();
151 }
152 }
153 };
154
155 Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
156 assert(_index < _args->length(), "out of bounds");
1498 if (vf->is_compiled_frame()) {
1499 // compiled method frame
1500 compiledVFrame* cvf = compiledVFrame::cast(vf);
1501
1502 ScopeDesc* scope = cvf->scope();
1503 // native wrappers do not have a scope
1504 if (scope != nullptr && scope->objects() != nullptr) {
1505 prev_cvf = cvf;
1506
1507 GrowableArray<ScopeValue*>* objects = nullptr;
1508 if (!realloc_called) {
1509 objects = scope->objects();
1510 } else {
1511 // some object might already have been re-allocated, only reallocate the non-allocated ones
1512 objects = get_unallocated_objects_or_null(scope->objects());
1513 }
1514
1515 if (objects != nullptr) {
1516 RegisterMap reg_map(vf->register_map());
1517 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL);
1518 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false, CHECK_NULL);
1519 realloc_called = true;
1520 }
1521
1522 GrowableArray<ScopeValue*>* local_values = scope->locals();
1523 for (int i = 0; i < local_values->length(); i++) {
1524 ScopeValue* value = local_values->at(i);
1525 assert(!value->is_object_merge(), "Should not be.");
1526 if (value->is_object()) {
1527 if (localIsVirtual_h.is_null()) {
1528 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1529 localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1530 }
1531 localIsVirtual_h->bool_at_put(i, true);
1532 }
1533 }
1534 }
1535
1536 locals = cvf->locals();
1537 frame_number = cvf->vframe_id();
1538 } else {
1748 break;
1749 }
1750 vf = vf->sender();
1751 }
1752
1753 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1754 if (last_frame_number >= virtualFrames->length()) {
1755 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1756 }
1757
1758 // Reallocate the non-escaping objects and restore their fields.
1759 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1760 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1761
1762 if (objects == nullptr) {
1763 // no objects to materialize
1764 return;
1765 }
1766
1767 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1768 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1769
1770 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1771 compiledVFrame* cvf = virtualFrames->at(frame_index);
1772
1773 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1774 StackValueCollection* locals = cvf->locals();
1775 if (locals != nullptr) {
1776 for (int i2 = 0; i2 < locals->size(); i2++) {
1777 StackValue* var = locals->at(i2);
1778 assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1779 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1780 jvalue val;
1781 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1782 cvf->update_local(T_OBJECT, i2, val);
1783 }
1784 }
1785 }
1786
1787 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1788 StackValueCollection* expressions = cvf->expressions();
2072 box_signature, &jargs, CHECK_NULL);
2073 oop hotspot_box = box_result.get_oop();
2074 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2075 return JVMCIENV->get_jobject(result);
2076 C2V_END
2077
2078 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2079 Klass* klass = UNPACK_PAIR(Klass, klass);
2080 if (klass == nullptr) {
2081 JVMCI_THROW_0(NullPointerException);
2082 }
2083 if (!klass->is_instance_klass()) {
2084 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2085 return JVMCIENV->get_jobjectArray(methods);
2086 }
2087
2088 InstanceKlass* iklass = InstanceKlass::cast(klass);
2089 GrowableArray<Method*> constructors_array;
2090 for (int i = 0; i < iklass->methods()->length(); i++) {
2091 Method* m = iklass->methods()->at(i);
2092 if (m->is_object_constructor()) {
2093 constructors_array.append(m);
2094 }
2095 }
2096 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2097 for (int i = 0; i < constructors_array.length(); i++) {
2098 methodHandle ctor(THREAD, constructors_array.at(i));
2099 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2100 JVMCIENV->put_object_at(methods, i, method);
2101 }
2102 return JVMCIENV->get_jobjectArray(methods);
2103 C2V_END
2104
2105 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2106 Klass* klass = UNPACK_PAIR(Klass, klass);
2107 if (klass == nullptr) {
2108 JVMCI_THROW_0(NullPointerException);
2109 }
2110 if (!klass->is_instance_klass()) {
2111 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2112 return JVMCIENV->get_jobjectArray(methods);
2113 }
2114
2115 InstanceKlass* iklass = InstanceKlass::cast(klass);
2116 GrowableArray<Method*> methods_array;
2117 for (int i = 0; i < iklass->methods()->length(); i++) {
2118 Method* m = iklass->methods()->at(i);
2119 if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
2120 methods_array.append(m);
2121 }
2122 }
2123 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2124 for (int i = 0; i < methods_array.length(); i++) {
2125 methodHandle mh(THREAD, methods_array.at(i));
2126 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2127 JVMCIENV->put_object_at(methods, i, method);
2128 }
2129 return JVMCIENV->get_jobjectArray(methods);
2130 C2V_END
2131
2132 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2133 Klass* klass = UNPACK_PAIR(Klass, klass);
2134 if (klass == nullptr) {
2135 JVMCI_THROW_0(NullPointerException);
2136 }
2137 if (!klass->is_instance_klass()) {
2138 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2139 }
2801 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2802 JVMCIObject code = JVMCIENV->wrap(code_handle);
2803 CodeBlob* cb = JVMCIENV->get_code_blob(code);
2804 if (cb == nullptr) {
2805 return nullptr;
2806 }
2807 // Make a resource copy of code before the allocation causes a safepoint
2808 int code_size = cb->code_size();
2809 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2810 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2811
2812 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2813 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2814 return JVMCIENV->get_jbyteArray(result);
2815 }
2816
2817 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2818 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2819 methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2820 oop executable;
2821 if (m->is_class_initializer()) {
2822 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2823 "Cannot create java.lang.reflect.Method for class initializer");
2824 }
2825 else if (m->is_object_constructor() || m->is_static_vnew_factory()) {
2826 executable = Reflection::new_constructor(m, CHECK_NULL);
2827 } else {
2828 executable = Reflection::new_method(m, false, CHECK_NULL);
2829 }
2830 return JNIHandles::make_local(THREAD, executable);
2831 }
2832
2833 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2834 if (!klass->is_instance_klass()) {
2835 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2836 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2837 }
2838 InstanceKlass* iklass = InstanceKlass::cast(klass);
2839 if (index < 0 || index > iklass->total_fields_count()) {
2840 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2841 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2842 }
2843 return iklass;
2844 }
2845
|