changeset 12806:69f78bcd65f8

8136931: more fine-grained condition checking for BMH species creation Reviewed-by: psandoz, sundar
author mhaupt
date Wed, 23 Sep 2015 08:43:51 +0200
parents 3c09abf433f0
children e35164a24594
files src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java
diffstat 3 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Tue Sep 22 11:01:54 2015 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Wed Sep 23 08:43:51 2015 +0200
@@ -404,6 +404,14 @@
             d = lookupCache(types);
             // Class loading must have upgraded the cache.
             assert(d != null && !d.isPlaceholder());
+            if (OBSERVE_BMH_SPECIES_CREATION) {
+                if (d == null) {
+                    throw new IllegalStateException("d == null");
+                }
+                if (d.isPlaceholder()) {
+                    throw new IllegalStateException("d is place holder");
+                }
+            }
             return d;
         }
         static SpeciesData getForClass(String types, Class<? extends BoundMethodHandle> clazz) {
@@ -415,6 +423,9 @@
             if (d != null)  return d;
             d = new SpeciesData(types);
             assert(d.isPlaceholder());
+            if (OBSERVE_BMH_SPECIES_CREATION && !d.isPlaceholder()) {
+                throw new IllegalStateException("d is not place holder");
+            }
             CACHE.put(types, d);
             return d;
         }
@@ -422,6 +433,15 @@
             SpeciesData d2;
             assert((d2 = CACHE.get(types)) == null || d2.isPlaceholder());
             assert(!d.isPlaceholder());
+            if (OBSERVE_BMH_SPECIES_CREATION) {
+                d2 = CACHE.get(types);
+                if (d2 != null && !d2.isPlaceholder()) {
+                    throw new IllegalStateException("non-null d2 is not place holder");
+                }
+                if (d.isPlaceholder()) {
+                    throw new IllegalStateException("d is place holder");
+                }
+            }
             CACHE.put(types, d);
             return d;
         }
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java	Tue Sep 22 11:01:54 2015 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java	Wed Sep 23 08:43:51 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, 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
@@ -51,8 +51,12 @@
     static final boolean PROFILE_GWT;
     static final int CUSTOMIZE_THRESHOLD;
 
+    // This is a temporary property added for improved error reporting; it will
+    // be removed once it has served its purpose.
+    static final boolean OBSERVE_BMH_SPECIES_CREATION;
+
     static {
-        final Object[] values = new Object[9];
+        final Object[] values = new Object[10];
         AccessController.doPrivileged(new PrivilegedAction<>() {
                 public Void run() {
                     values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
@@ -64,6 +68,7 @@
                     values[6] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0);
                     values[7] = Boolean.parseBoolean(System.getProperty("java.lang.invoke.MethodHandle.PROFILE_GWT", "true"));
                     values[8] = Integer.getInteger("java.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD", 127);
+                    values[9] = Boolean.getBoolean("java.lang.invoke.MethodHandle.OBSERVE_BMH_SPECIES_CREATION");
                     return null;
                 }
             });
@@ -77,6 +82,8 @@
         PROFILE_GWT               = (Boolean) values[7];
         CUSTOMIZE_THRESHOLD       = (Integer) values[8];
 
+        OBSERVE_BMH_SPECIES_CREATION = (Boolean) values[9];
+
         if (CUSTOMIZE_THRESHOLD < -1 || CUSTOMIZE_THRESHOLD > 127) {
             throw newInternalError("CUSTOMIZE_THRESHOLD should be in [-1...127] range");
         }
--- a/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java	Tue Sep 22 11:01:54 2015 -0700
+++ b/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java	Wed Sep 23 08:43:51 2015 +0200
@@ -32,7 +32,7 @@
  * @build LambdaFormTestCase
  * @build LFCachingTestCase
  * @build LFMultiThreadCachingTest
- * @run main/othervm LFMultiThreadCachingTest
+ * @run main/othervm -Djava.lang.invoke.MethodHandle.OBSERVE_BMH_SPECIES_CREATION=true LFMultiThreadCachingTest
  */
 
 import java.lang.invoke.MethodHandle;