--- old/src/hotspot/share/runtime/reflection.cpp 2019-04-24 13:36:47.000000000 -0700 +++ new/src/hotspot/share/runtime/reflection.cpp 2019-04-24 13:36:47.000000000 -0700 @@ -843,8 +843,7 @@ oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) { // Allow sun.reflect.ConstantPool to refer to methods as java.lang.reflect.Methods. - assert(!method()->is_initializer() || - (for_constant_pool_access && method()->is_static()), + assert(!method()->name()->starts_with('<') || for_constant_pool_access, "should call new_constructor instead"); InstanceKlass* holder = method->method_holder(); int slot = method->method_idnum(); @@ -894,7 +893,9 @@ oop Reflection::new_constructor(const methodHandle& method, TRAPS) { - assert(method()->is_initializer(), "should call new_method instead"); + assert(method()->is_object_constructor() || + method()->is_static_init_factory(), + "should call new_method instead"); InstanceKlass* holder = method->method_holder(); int slot = method->method_idnum(); @@ -1262,6 +1263,16 @@ // Create new instance (the receiver) klass->check_valid_for_instantiation(false, CHECK_NULL); + + // Special case for factory methods + if (!method->signature()->is_void_method_signature()) { + assert(klass->is_value(), "inline classes must use factory methods"); + Handle no_receiver; // null instead of receiver + return invoke(klass, method, no_receiver, override, ptypes, T_OBJECT, args, false, CHECK_NULL); + } + + // main branch of code creates a non-inline object: + assert(!klass->is_value(), "classic constructors are only for non-inline classes"); Handle receiver = klass->allocate_instance_handle(CHECK_NULL); // Ignore result from call and return receiver