8146201: [AOT] Class static initializers that are not pure should not be executed during static compilation

Reviewed-by: kvn
This commit is contained in:
Dean Long 2018-03-20 10:23:14 -07:00
parent 0df6b5baee
commit 91649ef44b
3 changed files with 14 additions and 11 deletions

View file

@ -480,6 +480,9 @@ C2V_END
C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
Klass* resolved_klass = cp->klass_at(index, CHECK_NULL); Klass* resolved_klass = cp->klass_at(index, CHECK_NULL);
if (resolved_klass->is_instance_klass()) {
InstanceKlass::cast(resolved_klass)->link_class_or_fail(THREAD);
}
oop klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL); oop klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL);
return JNIHandles::make_local(THREAD, klass); return JNIHandles::make_local(THREAD, klass);
C2V_END C2V_END

View file

@ -368,12 +368,6 @@ methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool,
if (holder_is_accessible) { // Our declared holder is loaded. if (holder_is_accessible) { // Our declared holder is loaded.
constantTag tag = cpool->tag_ref_at(index); constantTag tag = cpool->tag_ref_at(index);
methodHandle m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag); methodHandle m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag);
if (!m.is_null() &&
(bc == Bytecodes::_invokestatic
? InstanceKlass::cast(m->method_holder())->is_not_initialized()
: !InstanceKlass::cast(m->method_holder())->is_loaded())) {
m = NULL;
}
if (!m.is_null()) { if (!m.is_null()) {
// We found the method. // We found the method.
return m; return m;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -663,8 +663,12 @@ public final class HotSpotConstantPool implements ConstantPool, MetaspaceWrapper
} }
@Override @Override
@SuppressWarnings("fallthrough")
public void loadReferencedType(int cpi, int opcode) { public void loadReferencedType(int cpi, int opcode) {
loadReferencedType(cpi, opcode, true /* initialize */);
}
@SuppressWarnings("fallthrough")
public void loadReferencedType(int cpi, int opcode, boolean initialize) {
int index; int index;
switch (opcode) { switch (opcode) {
case Bytecodes.CHECKCAST: case Bytecodes.CHECKCAST:
@ -718,9 +722,11 @@ public final class HotSpotConstantPool implements ConstantPool, MetaspaceWrapper
case UnresolvedClass: case UnresolvedClass:
case UnresolvedClassInError: case UnresolvedClassInError:
final HotSpotResolvedObjectTypeImpl type = compilerToVM().resolveTypeInPool(this, index); final HotSpotResolvedObjectTypeImpl type = compilerToVM().resolveTypeInPool(this, index);
Class<?> klass = type.mirror(); if (initialize) {
if (!klass.isPrimitive() && !klass.isArray()) { Class<?> klass = type.mirror();
UNSAFE.ensureClassInitialized(klass); if (!klass.isPrimitive() && !klass.isArray()) {
UNSAFE.ensureClassInitialized(klass);
}
} }
if (tag == JVM_CONSTANT.MethodRef) { if (tag == JVM_CONSTANT.MethodRef) {
if (Bytecodes.isInvokeHandleAlias(opcode) && isSignaturePolymorphicHolder(type)) { if (Bytecodes.isInvokeHandleAlias(opcode) && isSignaturePolymorphicHolder(type)) {