changeset 4553:82bacd23c0fa

8006267: InterfaceMethod_ref should allow invokestatic and invokespecial Contributed-by: Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
author mduigou
date Wed, 17 Apr 2013 11:23:12 -0700
parents e7a0d98ad106
children dbaf870dc203
files src/share/vm/classfile/classFileParser.cpp src/share/vm/interpreter/linkResolver.cpp src/share/vm/prims/methodHandles.cpp
diffstat 3 files changed, 36 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classFileParser.cpp	Tue Apr 16 14:33:26 2013 -0700
+++ b/src/share/vm/classfile/classFileParser.cpp	Wed Apr 17 11:23:12 2013 -0700
@@ -436,14 +436,19 @@
               ref_index, CHECK_(nullHandle));
             break;
           case JVM_REF_invokeVirtual:
-          case JVM_REF_invokeStatic:
-          case JVM_REF_invokeSpecial:
           case JVM_REF_newInvokeSpecial:
             check_property(
               tag.is_method(),
               "Invalid constant pool index %u in class file %s (not a method)",
               ref_index, CHECK_(nullHandle));
             break;
+          case JVM_REF_invokeStatic:
+          case JVM_REF_invokeSpecial:
+            check_property(
+               tag.is_method() || tag.is_interface_method(),
+               "Invalid constant pool index %u in class file %s (not a method)",
+               ref_index, CHECK_(nullHandle));
+             break;
           case JVM_REF_invokeInterface:
             check_property(
               tag.is_interface_method(),
@@ -3840,7 +3845,7 @@
     }
 
     if (TraceClassLoadingPreorder) {
-      tty->print("[Loading %s", name->as_klass_external_name());
+      tty->print("[Loading %s", (name != NULL) ? name->as_klass_external_name() : "NoName");
       if (cfs->source() != NULL) tty->print(" from %s", cfs->source());
       tty->print_cr("]");
     }
--- a/src/share/vm/interpreter/linkResolver.cpp	Tue Apr 16 14:33:26 2013 -0700
+++ b/src/share/vm/interpreter/linkResolver.cpp	Wed Apr 17 11:23:12 2013 -0700
@@ -1010,13 +1010,28 @@
                                                       resolved_method->name(),
                                                       resolved_method->signature()));
   }
-  // check if public
-  if (!sel_method->is_public()) {
-    ResourceMark rm(THREAD);
-    THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
-              Method::name_and_sig_as_C_string(recv_klass(),
-                                                      sel_method->name(),
-                                                      sel_method->signature()));
+  // check access
+  if (sel_method->method_holder()->is_interface()) {
+    // Method holder is an interface. Throw Illegal Access Error if sel_method
+    // is neither public nor private.
+    if (!(sel_method->is_public() || sel_method->is_private())) {
+      ResourceMark rm(THREAD);
+      THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
+                Method::name_and_sig_as_C_string(recv_klass(),
+                                                 sel_method->name(),
+                                                 sel_method->signature()));
+    }
+  }
+  else {
+    // Method holder is a class. Throw Illegal Access Error if sel_method
+    // is not public.
+    if (!sel_method->is_public()) {
+      ResourceMark rm(THREAD);
+      THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
+                Method::name_and_sig_as_C_string(recv_klass(),
+                                                 sel_method->name(),
+                                                 sel_method->signature()));
+    }
   }
   // check if abstract
   if (check_null_and_abstract && sel_method->is_abstract()) {
--- a/src/share/vm/prims/methodHandles.cpp	Tue Apr 16 14:33:26 2013 -0700
+++ b/src/share/vm/prims/methodHandles.cpp	Wed Apr 17 11:23:12 2013 -0700
@@ -187,13 +187,13 @@
     flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
   } else if (mods.is_static()) {
     flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT);
-    // Check if this method is a lambda method that is genrated as
-    // private static method.
-    if (m->is_private() && m->is_synthetic() && m->method_holder()->is_interface()) {
-      vmindex = klassItable::compute_itable_index(m);
-    }
+     // Check if this method is a lambda method that is generated as
+     // private static method.
+     if (m->is_private() && m->method_holder()->is_interface()) {
+       vmindex = klassItable::compute_itable_index(m);
+     }
   } else if (receiver_limit != mklass &&
-             !receiver_limit->is_subtype_of(mklass)) {
+            !receiver_limit->is_subtype_of(mklass)) {
     return NULL;  // bad receiver limit
   } else if (receiver_limit->is_interface() &&
              mklass->is_interface()) {