changeset 5705:d31bebcd5635

Merge
author henryjen
date Wed, 06 Nov 2013 11:36:44 -0800
parents 7fd913010dbb (current diff) 36b4e9b30322 (diff)
children fc7177e457bf
files .hgtags .jcheck/conf make/jprt.properties src/share/vm/classfile/systemDictionary.cpp src/share/vm/classfile/vmSymbols.hpp src/share/vm/interpreter/linkResolver.cpp src/share/vm/oops/constantPool.cpp src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/instanceKlass.hpp src/share/vm/prims/methodHandles.cpp src/share/vm/runtime/globals.hpp
diffstat 8 files changed, 139 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Tue Oct 29 14:56:30 2013 -0700
+++ b/.hgtags	Wed Nov 06 11:36:44 2013 -0800
@@ -273,6 +273,7 @@
 54240c1b8e87758f28da2c6a569a926fd9e0910a jdk8-b53
 9e3ae661284dc04185b029d85440fe7811f1ed07 hs24-b21
 e8fb566b94667f88462164defa654203f0ab6820 jdk8-b54
+203d2c0ee7c4fe648464fe2c506bd91003b7a5b7 lambda-b56
 09ea7e0752b306b8ae74713aeb4eb6263e1c6836 hs24-b22
 af0c8a0808516317333dcf9af15567cdd52761ce jdk8-b55
 6124ff4218296c91e4a72f1a76c064892d39d61b jdk8-b56
--- a/.jcheck/conf	Tue Oct 29 14:56:30 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-project=jdk8
--- a/src/share/vm/classfile/classFileParser.cpp	Tue Oct 29 14:56:30 2013 -0700
+++ b/src/share/vm/classfile/classFileParser.cpp	Wed Nov 06 11:36:44 2013 -0800
@@ -2396,6 +2396,7 @@
       runtime_visible_type_annotations_length +
            runtime_invisible_type_annotations_length,
       annotation_default_length,
+      0,
       0);
 
   Method* m = Method::allocate(
--- a/src/share/vm/oops/constMethod.cpp	Tue Oct 29 14:56:30 2013 -0700
+++ b/src/share/vm/oops/constMethod.cpp	Wed Nov 06 11:36:44 2013 -0800
@@ -137,6 +137,9 @@
   if (sizes->default_annotations_length() > 0) {
     extra_bytes += sizeof(AnnotationArray*);
   }
+  if (sizes->target_method_length() > 0) {
+    extra_bytes += sizeof(Method*);
+  }
 
   int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
   assert(extra_words == extra_bytes/BytesPerWord, "should already be aligned");
@@ -163,6 +166,7 @@
   if (has_parameter_annotations()) offset++;
   if (has_type_annotations()) offset++;
   if (has_default_annotations()) offset++;
+  if (has_target_method()) offset++;
   return (u2*)((AnnotationArray**)constMethod_end() - offset) - 1;
 }
 
@@ -256,6 +260,8 @@
     _flags |= _has_type_annotations;
   if (sizes->default_annotations_length() > 0)
     _flags |= _has_default_annotations;
+  if (sizes->target_method_length() > 0)
+    _flags |= _has_target_method;
 
   // This code is extremely brittle and should possibly be revised.
   // The *_length_addr functions walk backwards through the
@@ -363,6 +369,16 @@
   return (AnnotationArray**)constMethod_end() - offset;
 }
 
+Method** ConstMethod::target_method_addr() const {
+  assert(has_target_method(), "should only be called if overpass target method is present");
+  int offset = 1;
+  if (has_method_annotations()) offset++;
+  if (has_parameter_annotations()) offset++;
+  if (has_type_annotations()) offset++;
+  if (has_default_annotations()) offset++;
+  return (Method**)constMethod_end() - offset;
+}
+
 // copy annotations from 'cm' to 'this'
 void ConstMethod::copy_annotations_from(ConstMethod* cm) {
   if (cm->has_method_annotations()) {
--- a/src/share/vm/oops/constMethod.hpp	Tue Oct 29 14:56:30 2013 -0700
+++ b/src/share/vm/oops/constMethod.hpp	Wed Nov 06 11:36:44 2013 -0800
@@ -86,6 +86,9 @@
 // | generic signature index (u2)                         |
 // |  (indexed from start of constMethodOop)              |
 // |------------------------------------------------------|
+// | word-aligned Method* target_method if overpass       |
+// |  (access flags bit tells if present)                 |
+// |------------------------------------------------------|
 // | annotations arrays - method, parameter, type, default|
 // | pointer to Array<u1> if annotation is present        |
 // |------------------------------------------------------|
@@ -141,7 +144,8 @@
   do_element(method_annotations_length)         \
   do_element(parameter_annotations_length)      \
   do_element(type_annotations_length)           \
-  do_element(default_annotations_length)
+  do_element(default_annotations_length)        \
+  do_element(target_method_length)
 
 #define INLINE_TABLE_DECLARE(sym)    int _##sym;
 #define INLINE_TABLE_PARAM(sym)      int sym,
@@ -193,7 +197,8 @@
     _has_method_annotations = 0x0080,
     _has_parameter_annotations = 0x0100,
     _has_type_annotations = 0x0200,
-    _has_default_annotations = 0x0400
+    _has_default_annotations = 0x0400,
+    _has_target_method = 0x0800
   };
 
   // Bit vector of signature
@@ -395,6 +400,8 @@
   bool has_default_annotations() const
     { return (_flags & _has_default_annotations) != 0; }
 
+  bool has_target_method() const
+    { return (_flags & _has_target_method) != 0; }
 
   AnnotationArray** method_annotations_addr() const;
   AnnotationArray* method_annotations() const  {
@@ -428,6 +435,15 @@
     *(default_annotations_addr()) = anno;
   }
 
+  Method** target_method_addr() const;
+  Method* target_method() const {
+    return has_target_method() ? *(target_method_addr()) : NULL;
+  }
+  void set_target_method(Method* target) {
+    assert(has_target_method(), "only set target method for OVERPASS");
+    *(target_method_addr()) = target;
+  }
+
   int method_annotations_length() const {
     return has_method_annotations() ? method_annotations()->length() : 0;
   }
@@ -440,6 +456,11 @@
   int default_annotations_length() const {
     return has_default_annotations() ? default_annotations()->length() : 0;
   }
+  // This is just used to determine existence, not to count length
+  // returning nonzero is sufficient
+  int target_method_length() const {
+    return has_target_method() ? sizeof(Method*) : 0;
+  }
 
   // Copy annotations from other ConstMethod
   void copy_annotations_from(ConstMethod* cm);
--- a/src/share/vm/oops/method.cpp	Tue Oct 29 14:56:30 2013 -0700
+++ b/src/share/vm/oops/method.cpp	Wed Nov 06 11:36:44 2013 -0800
@@ -1150,6 +1150,7 @@
   int parameter_annotations_len = cm->parameter_annotations_length();
   int type_annotations_len = cm->type_annotations_length();
   int default_annotations_len = cm->default_annotations_length();
+  int target_method_len = cm->target_method_length();
 
   InlineTableSizes sizes(
       localvariable_len,
@@ -1162,6 +1163,7 @@
       parameter_annotations_len,
       type_annotations_len,
       default_annotations_len,
+      target_method_len,
       0);
 
   ClassLoaderData* loader_data = m->method_holder()->class_loader_data();
--- a/src/share/vm/oops/method.hpp	Tue Oct 29 14:56:30 2013 -0700
+++ b/src/share/vm/oops/method.hpp	Wed Nov 06 11:36:44 2013 -0800
@@ -198,7 +198,11 @@
   AnnotationArray* type_annotations() const      {
     return constMethod()->type_annotations();
   }
-
+  // overpass support
+  void set_target_method(Method* target)         {
+     constMethod()->set_target_method(target); 
+  }
+  Method* target_method() const                  { return constMethod()->target_method(); }
 #ifdef CC_INTERP
   void set_result_index(BasicType type);
   int  result_index()                            { return _result_index; }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/8026365/InvokeSpecialAnonTest.java	Wed Nov 06 11:36:44 2013 -0800
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8026365
+ * @summary Test invokespecial of host class method from an anonymous class
+ * @author  Robert Field
+ * @library /testlibrary
+ * @compile -XDignore.symbol.file InvokeSpecialAnonTest.java
+ * @run main ClassFileInstaller InvokeSpecialAnonTest AnonTester
+ * @run main/othervm -Xbootclasspath/a:. -Xverify:all InvokeSpecialAnonTest
+ */
+import jdk.internal.org.objectweb.asm.*;
+import java.lang.reflect.Constructor;
+import sun.misc.Unsafe;
+
+public class InvokeSpecialAnonTest implements Opcodes {
+
+    static byte[] anonClassBytes() throws Exception {
+        ClassWriter cw = new ClassWriter(0);
+        MethodVisitor mv;
+
+        cw.visit(V1_8, ACC_FINAL + ACC_SUPER, "Anon", null, "java/lang/Object", null);
+
+        {
+            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(2, 2);
+            mv.visitEnd();
+        }
+        {
+            mv = cw.visitMethod(ACC_PUBLIC, "m", "(LInvokeSpecialAnonTest;)I", null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitVarInsn(ALOAD, 1);
+            mv.visitMethodInsn(INVOKESPECIAL, "InvokeSpecialAnonTest", "privMethod", "()I");
+            mv.visitInsn(IRETURN);
+            mv.visitMaxs(2, 3);
+            mv.visitEnd();
+        }
+        cw.visitEnd();
+
+        return cw.toByteArray();
+    }
+
+    private int privMethod() { return 1234; }
+
+    public static void main(String[] args) throws Exception {
+        Class<?> klass = InvokeSpecialAnonTest.class;
+        try {
+           Class<?> result = AnonTester.defineTest(klass, anonClassBytes());
+           System.out.println("Passed.");
+        } catch (Exception e) {
+           e.printStackTrace();
+           throw e;
+        }
+    }
+}
+
+
+class AnonTester {
+    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
+
+    public static Class<?> defineTest(Class<?> targetClass, byte[] classBytes) throws Exception {
+        return UNSAFE.defineAnonymousClass(targetClass, classBytes, null);
+    }
+}