< prev index next > src/hotspot/share/runtime/reflection.cpp
Print this page
#include "jvm.h"
#include "logging/log.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
+ #include "oops/inlineKlass.inline.hpp"
#include "oops/instanceKlass.inline.hpp"
#include "oops/klass.inline.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/objArrayOop.inline.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/javaThread.hpp"
#include "runtime/reflection.hpp"
#include "runtime/signature.hpp"
#include "runtime/vframe.inline.hpp"
#include "utilities/formatBuffer.hpp"
+ #include "utilities/globalDefinitions.hpp"
static void trace_class_resolution(oop mirror) {
if (mirror == nullptr || java_lang_Class::is_primitive(mirror)) {
return;
}
void Reflection::array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS) {
if (!a->is_within_bounds(index)) {
THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
}
+
if (a->is_objArray()) {
if (value_type == T_OBJECT) {
oop obj = cast_to_oop(value->l);
+ if (a->is_null_free_array() && obj == nullptr) {
+ THROW_MSG(vmSymbols::java_lang_NullPointerException(), "null-restricted array");
+ }
+
if (obj != nullptr) {
Klass* element_klass = ObjArrayKlass::cast(a->klass())->element_klass();
if (!obj->is_a(element_klass)) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "array element type mismatch");
}
}
static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
ResolvingSignatureStream ss(signature, k, false);
oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);
- if (log_is_enabled(Debug, class, resolve)) {
- trace_class_resolution(nt);
- }
return Handle(THREAD, nt);
}
oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
// Allow jdk.internal.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
- assert(!method()->is_object_initializer() &&
- (for_constant_pool_access || !method()->is_static_initializer()),
- "Should not be the initializer");
+ assert(!method()->name()->starts_with('<') || for_constant_pool_access,
+ "should call new_constructor instead");
InstanceKlass* holder = method->method_holder();
int slot = method->method_idnum();
Symbol* signature = method->signature();
int parameter_count = ArgumentCount(signature).size();
return mh();
}
oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
- assert(method()->is_object_initializer(), "Should be the initializer");
+ assert(method()->is_object_constructor(),
+ "should call new_method instead");
InstanceKlass* holder = method->method_holder();
int slot = method->method_idnum();
Symbol* signature = method->signature();
java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
java_lang_reflect_Field::set_slot(rh(), fd->index());
java_lang_reflect_Field::set_name(rh(), name());
java_lang_reflect_Field::set_type(rh(), type());
+
+ int flags = 0;
if (fd->is_trusted_final()) {
- java_lang_reflect_Field::set_trusted_final(rh());
+ flags |= TRUSTED_FINAL;
+ }
+ if (fd->is_null_free_inline_type()) {
+ flags |= NULL_RESTRICTED;
}
+ java_lang_reflect_Field::set_flags(rh(), flags);
+
// Note the ACC_ANNOTATION bit, which is a per-class access flag, is never set here.
- java_lang_reflect_Field::set_modifiers(rh(), fd->access_flags().as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
+ int modifiers = fd->access_flags().as_int();
+ java_lang_reflect_Field::set_modifiers(rh(), modifiers);
java_lang_reflect_Field::set_override(rh(), false);
if (fd->has_generic_signature()) {
Symbol* gs = fd->generic_signature();
Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
java_lang_reflect_Field::set_signature(rh(), sig());
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
}
// target klass is receiver's klass
target_klass = receiver->klass();
// no need to resolve if method is private or <init>
- if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) {
+ if (reflected_method->is_private() ||
+ reflected_method->name() == vmSymbols::object_initializer_name()) {
method = reflected_method;
} else {
// resolve based on the receiver
if (reflected_method->method_holder()->is_interface()) {
// resolve interface call
Method* m = klass->method_with_idnum(slot);
if (m == nullptr) {
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "invoke");
}
methodHandle method(THREAD, m);
- assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor");
// Make sure klass gets initialize
klass->initialize(CHECK_NULL);
// Create new instance (the receiver)
< prev index next >