changeset 434:3e703c2acebc

anno-stable.patch: tweak naming, apply to LFs etc.
author jrose
date Mon, 15 Oct 2012 17:48:20 -0700
parents 2a2a02876510
children bb9c6901db85
files anno-stable.patch series
diffstat 2 files changed, 223 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/anno-stable.patch	Wed Sep 26 00:10:40 2012 -0700
+++ b/anno-stable.patch	Mon Oct 15 17:48:20 2012 -0700
@@ -1,9 +1,113 @@
 Summary: @Stable annotation for constant folding of lazily evaluated variables.
 
-diff --git a/src/share/classes/java/lang/invoke/Stable.java b/src/share/classes/java/lang/invoke/Stable.java
+diff --git a/src/share/classes/java/lang/invoke/LambdaForm.java b/src/share/classes/java/lang/invoke/LambdaForm.java
+--- a/src/share/classes/java/lang/invoke/LambdaForm.java
++++ b/src/share/classes/java/lang/invoke/LambdaForm.java
+@@ -34,6 +34,7 @@
+ import java.util.HashMap;
+ import java.util.concurrent.ConcurrentHashMap;
+ import sun.invoke.util.Wrapper;
++import sun.invoke.Stable;
+ import static java.lang.invoke.MethodHandleStatics.*;
+ import static java.lang.invoke.MethodHandleNatives.Constants.*;
+ import java.lang.reflect.Field;
+@@ -120,7 +121,7 @@
+ class LambdaForm {
+     final int arity;
+     final int result;
+-    final Name[] names;
++    @Stable final Name[] names;
+     final String debugName;
+     MemberName vmentry;   // low-level behavior, or null if not yet prepared
+     private boolean isCompiled;
+@@ -969,8 +970,8 @@
+ 
+     static class NamedFunction {
+         final MemberName member;
+-        MethodHandle resolvedHandle;
+-        MethodHandle invoker;
++        @Stable MethodHandle resolvedHandle;
++        @Stable MethodHandle invoker;
+ 
+         NamedFunction(MethodHandle resolvedHandle) {
+             this(resolvedHandle.internalMemberName(), resolvedHandle);
+@@ -1265,7 +1266,7 @@
+         final char type;
+         private short index;
+         final NamedFunction function;
+-        final Object[] arguments;
++        @Stable final Object[] arguments;
+ 
+         private Name(int index, char type, NamedFunction function, Object[] arguments) {
+             this.index = (short)index;
+diff --git a/src/share/classes/java/lang/invoke/MethodHandle.java b/src/share/classes/java/lang/invoke/MethodHandle.java
+--- a/src/share/classes/java/lang/invoke/MethodHandle.java
++++ b/src/share/classes/java/lang/invoke/MethodHandle.java
+@@ -419,6 +419,7 @@
+ 
+     private final MethodType type;
+     /*private*/ final LambdaForm form;
++    //@@ FIXME: MAKE @Stable
+     // form is not private so that invokers can easily fetch it
+ 
+     /**
+diff --git a/src/share/classes/java/lang/invoke/MethodType.java b/src/share/classes/java/lang/invoke/MethodType.java
+--- a/src/share/classes/java/lang/invoke/MethodType.java
++++ b/src/share/classes/java/lang/invoke/MethodType.java
+@@ -33,6 +33,7 @@
+ import java.util.List;
+ import sun.invoke.util.BytecodeDescriptor;
+ import static java.lang.invoke.MethodHandleStatics.*;
++import sun.invoke.Stable;
+ import sun.invoke.util.VerifyType;
+ 
+ /**
+@@ -91,9 +92,9 @@
+     private final Class<?>[] ptypes;
+ 
+     // The remaining fields are caches of various sorts:
+-    private MethodTypeForm form; // erased form, plus cached data about primitives
+-    private MethodType wrapAlt;  // alternative wrapped/unwrapped version
+-    private Invokers invokers;   // cache of handy higher-order adapters
++    private @Stable MethodTypeForm form; // erased form, plus cached data about primitives
++    private @Stable MethodType wrapAlt;  // alternative wrapped/unwrapped version
++    private @Stable Invokers invokers;   // cache of handy higher-order adapters
+ 
+     /**
+      * Check the given parameters for validity and store them into the final fields.
+diff --git a/src/share/classes/java/lang/invoke/MethodTypeForm.java b/src/share/classes/java/lang/invoke/MethodTypeForm.java
+--- a/src/share/classes/java/lang/invoke/MethodTypeForm.java
++++ b/src/share/classes/java/lang/invoke/MethodTypeForm.java
+@@ -28,6 +28,7 @@
+ import sun.invoke.util.Wrapper;
+ import static java.lang.invoke.MethodHandleStatics.*;
+ import static java.lang.invoke.MethodHandleNatives.Constants.*;
++import sun.invoke.Stable;
+ 
+ /**
+  * Shared information for a group of method types, which differ
+@@ -51,12 +52,13 @@
+     final MethodType basicType;         // the canonical erasure, with primitives simplified
+ 
+     // Cached adapter information:
+-    /*lazy*/ MethodHandle genericInvoker; // JVM hook for inexact invoke
+-    /*lazy*/ MethodHandle basicInvoker;   // cached instance of MH.invokeBasic
+-    /*lazy*/ MethodHandle namedFunctionInvoker; // cached helper for LF.NamedFunction
++    @Stable String typeString;           // argument type signature characters
++    @Stable MethodHandle genericInvoker; // JVM hook for inexact invoke
++    @Stable MethodHandle basicInvoker;   // cached instance of MH.invokeBasic
++    @Stable MethodHandle namedFunctionInvoker; // cached helper for LF.NamedFunction
+ 
+     // Cached lambda form information, for basic types only:
+-    final LambdaForm[] lambdaForms;
++    final @Stable LambdaForm[] lambdaForms;
+     // Indexes into lambdaForms:
+     static final int
+             LF_INVVIRTUAL     =  0,  // DMH invokeVirtual
+diff --git a/src/share/classes/sun/invoke/Stable.java b/src/share/classes/sun/invoke/Stable.java
 new file mode 100644
 --- /dev/null
-+++ b/src/share/classes/java/lang/invoke/Stable.java
++++ b/src/share/classes/sun/invoke/Stable.java
 @@ -0,0 +1,74 @@
 +/*
 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
@@ -30,7 +134,7 @@
 + * questions.
 + */
 +
-+package java.lang.invoke;
++package sun.invoke;
 +
 +import java.lang.annotation.*;
 +
@@ -74,8 +178,122 @@
 + * model would appear to be broken, if such a constant (the second value of the field)
 + * is used as the value of the field even after the field value has changed.
 + */
-+/*non-public*/
++public
 +@Target(ElementType.FIELD)
 +@Retention(RetentionPolicy.RUNTIME)
 +@interface Stable {
 +}
+diff --git a/test/sun/invoke/StableValueTest.java b/test/sun/invoke/StableValueTest.java
+new file mode 100644
+--- /dev/null
++++ b/test/sun/invoke/StableValueTest.java
+@@ -0,0 +1,109 @@
++/*
++ * Copyright (c) 2012, 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.  Oracle designates this
++ * particular file as subject to the "Classpath" exception as provided
++ * by Oracle in the LICENSE file that accompanied this code.
++ *
++ * 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
++ * @summary test inlining of elements of stable arrays
++ * @compile StableValueTest.java
++ * @run main/othervm
++ *        -Xbatch
++ *        -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
++ *        -XX:CompileCommand=compileonly,*StableValueTest::test
++ *        -XX:-TieredCompilation -XX:-UseTypeProfile
++ *        -XX:+FoldStableValues
++ *        -XX:+PrintCompilation -XX:+PrintInlining
++ *          test.sun.invoke.StableValueTest
++ */
++
++package test.sun.invoke;
++import sun.invoke.Stable;
++
++import java.util.*;
++
++public class StableValueTest {
++    static class Node {
++        final Object tree;
++        @Stable String label;
++        @Stable Node[] children;
++        Node(Object tree) {
++            this.tree = tree;
++        }
++        Node expand() {
++            if (children != null)
++                return this;
++            if (tree instanceof Object[]) {
++                Object[] a = (Object[]) tree;
++                Node[] children = new Node[a.length];
++                for (int i = 0; i < a.length; i++) {
++                    Object t = a[i];
++                    children[i] = (t instanceof Node) ? (Node)t : new Node(t);
++                }
++                this.children = children;
++            } else {
++                label = tree.toString();
++                children = new Node[0];
++            }
++            return this;
++        }
++        Node[] children() {
++            if (children == null) expand();
++            return children;
++        }
++        public String toString() {
++            expand();
++            return (label != null) ? label : "N"+Arrays.toString(children);
++        }
++    }
++
++    @Stable static Object[][] NODE_TABLE;
++    static @Stable int VERBOSITY;
++
++    public static void main(String... av) {
++        VERBOSITY = (av.length + 1);  // non-zero value!
++        NODE_TABLE = new Object[3][5];
++        ArrayList<Node> nodes = new ArrayList<>();
++        for (int i = 0; i < 3*5; i++) {
++            Node n = new Node(i);
++            if (i % 2 == 0) {
++                nodes.add(n);
++                n = new Node(nodes.toArray());
++            }
++            NODE_TABLE[i/5][i%5] = n;
++            if (VERBOSITY > 1)  System.out.println(n.toString());
++        }
++        if (VERBOSITY > 1)  System.out.println(NODE_TABLE[2][4].toString());
++        for (int i = 0; i < 100; i++) {
++            test(1000);
++        }
++    }
++
++    static String test(int count) {
++        String x = null;
++        for (int i = 0; i < count; i++) {
++            x = NODE_TABLE[2][4].toString();
++        }
++        return x;
++    }
++}
--- a/series	Wed Sep 26 00:10:40 2012 -0700
+++ b/series	Mon Oct 15 17:48:20 2012 -0700
@@ -6,7 +6,7 @@
 # review pending before push to hotspot-comp:
 
 # non-pushed files are under review or development, or merely experimental:
-anno-stable.patch               #-/meth #+1dde94130b0c #-buildable
+anno-stable.patch               #-/meth #+1dde94130b0c
 meth-info-7087570.patch         #-/meth #+1dde94130b0c
 meth.patch                      #-/meth #+1dde94130b0c
 meth-7177472.patch              #-/meth #+1dde94130b0c #-buildable