8146201: [AOT] Class static initializers that are not pure should not be executed during static compilation
authordlong
Tue, 20 Mar 2018 10:23:14 -0700
changeset 49467 74db2b7cec75
parent 49466 6ce398fe53fd
child 49468 bef5683e363d
8146201: [AOT] Class static initializers that are not pure should not be executed during static compilation Reviewed-by: kvn
src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
src/hotspot/share/jvmci/jvmciEnv.cpp
src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Tue Mar 20 15:59:36 2018 +0100
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Tue Mar 20 10:23:14 2018 -0700
@@ -480,6 +480,9 @@
 C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index))
   constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool);
   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);
   return JNIHandles::make_local(THREAD, klass);
 C2V_END
--- a/src/hotspot/share/jvmci/jvmciEnv.cpp	Tue Mar 20 15:59:36 2018 +0100
+++ b/src/hotspot/share/jvmci/jvmciEnv.cpp	Tue Mar 20 10:23:14 2018 -0700
@@ -368,12 +368,6 @@
   if (holder_is_accessible) { // Our declared holder is loaded.
     constantTag tag = cpool->tag_ref_at(index);
     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()) {
       // We found the method.
       return m;
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java	Tue Mar 20 15:59:36 2018 +0100
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java	Tue Mar 20 10:23:14 2018 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -663,8 +663,12 @@
     }
 
     @Override
+    public void loadReferencedType(int cpi, int opcode) {
+        loadReferencedType(cpi, opcode, true /* initialize */);
+    }
+
     @SuppressWarnings("fallthrough")
-    public void loadReferencedType(int cpi, int opcode) {
+    public void loadReferencedType(int cpi, int opcode, boolean initialize) {
         int index;
         switch (opcode) {
             case Bytecodes.CHECKCAST:
@@ -718,9 +722,11 @@
             case UnresolvedClass:
             case UnresolvedClassInError:
                 final HotSpotResolvedObjectTypeImpl type = compilerToVM().resolveTypeInPool(this, index);
-                Class<?> klass = type.mirror();
-                if (!klass.isPrimitive() && !klass.isArray()) {
-                    UNSAFE.ensureClassInitialized(klass);
+                if (initialize) {
+                    Class<?> klass = type.mirror();
+                    if (!klass.isPrimitive() && !klass.isArray()) {
+                        UNSAFE.ensureClassInitialized(klass);
+                    }
                 }
                 if (tag == JVM_CONSTANT.MethodRef) {
                     if (Bytecodes.isInvokeHandleAlias(opcode) && isSignaturePolymorphicHolder(type)) {