diff --git a/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java b/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java index 5be48729d5a..612ff09f138 100644 --- a/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java +++ b/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, 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 @@ -55,14 +55,36 @@ interface LiveStackFrame extends StackFrame { * *
A single local variable can hold a value of type boolean, byte, char, * short, int, float, reference or returnAddress. A pair of local variables - * can hold a value of type long or double. In other words, - * a value of type long or type double occupies two consecutive local - * variables. For a value of primitive type, the element in the - * local variable array is an {@link PrimitiveValue} object; - * otherwise, the element is an {@code Object}. + * can hold a value of type long or double (JVMS section 2.6.1). Primitive + * locals are represented in the returned array as {@code PrimitiveSlot}s, + * with longs and doubles occupying a pair of consecutive + * {@code PrimitiveSlot}s. * - *
The returned array may contain null entries if a local variable is not - * live. + *
The current VM implementation does not provide specific type + * information for primitive locals. This method simply returns the raw + * contents of the VM's primitive locals on a best-effort basis, without + * indicating a specific type. + * + *
The returned array may contain null entries for local variables that + * are not live. + * + * @implNote + *
The specific subclass of {@code PrimitiveSlot} will reflect the + * underlying architecture, and will be either {@code PrimitiveSlot32} or + * {@code PrimitiveSlot64}. + * + *
How a long or double value is stored in the pair of + * {@code PrimitiveSlot}s can vary based on the underlying architecture and + * VM implementation. On 32-bit architectures, long/double values are split + * between the two {@code PrimitiveSlot32}s. + * On 64-bit architectures, the entire value may be stored in one of the + * {@code PrimitiveSlot64}s, with the other {@code PrimitiveSlot64} being + * unused. + * + *
The contents of the unused, high-order portion of a + * {@code PrimitiveSlot64} (when storing a primitive other than a long or + * double) is unspecified. In particular, the unused bits are not + * necessarily zeroed out. * * @return the local variable array of this stack frame. */ @@ -78,7 +100,7 @@ interface LiveStackFrame extends StackFrame { *
Each entry on the operand stack can hold a value of any Java Virtual * Machine Type. * For a value of primitive type, the element in the returned array is - * an {@link PrimitiveValue} object; otherwise, the element is the {@code Object} + * a {@link PrimitiveSlot} object; otherwise, the element is the {@code Object} * on the operand stack. * * @return the operand stack of this stack frame. @@ -87,107 +109,37 @@ interface LiveStackFrame extends StackFrame { /** * UNSUPPORTED This interface is intended to be package-private - * or move to an internal package.
+ * or moved to an internal package.
*
- * Represents a local variable or an entry on the operand whose value is
+ * Represents a local variable or an entry on the operand stack whose value is
* of primitive type.
*/
- public abstract class PrimitiveValue {
+ public abstract class PrimitiveSlot {
/**
- * Returns the base type of this primitive value, one of
- * {@code B, D, C, F, I, J, S, Z}.
- *
- * @return Name of a base type
- * @jvms table 4.3-A
+ * Returns the size, in bytes, of the slot.
*/
- abstract char type();
+ public abstract int size();
/**
- * Returns the boolean value if this primitive value is of type boolean.
- * @return the boolean value if this primitive value is of type boolean.
+ * Returns the int value if this primitive value is of size 4
+ * @return the int value if this primitive value is of size 4
*
* @throws UnsupportedOperationException if this primitive value is not
- * of type boolean.
- */
- public boolean booleanValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the int value if this primitive value is of type int.
- * @return the int value if this primitive value is of type int.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type int.
+ * of size 4.
*/
public int intValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
+ throw new UnsupportedOperationException("this " + size() + "-byte primitive");
}
/**
- * Returns the long value if this primitive value is of type long.
- * @return the long value if this primitive value is of type long.
+ * Returns the long value if this primitive value is of size 8
+ * @return the long value if this primitive value is of size 8
*
* @throws UnsupportedOperationException if this primitive value is not
- * of type long.
+ * of size 8.
*/
public long longValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the char value if this primitive value is of type char.
- * @return the char value if this primitive value is of type char.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type char.
- */
- public char charValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the byte value if this primitive value is of type byte.
- * @return the byte value if this primitive value is of type byte.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type byte.
- */
- public byte byteValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the short value if this primitive value is of type short.
- * @return the short value if this primitive value is of type short.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type short.
- */
- public short shortValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the float value if this primitive value is of type float.
- * @return the float value if this primitive value is of type float.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type float.
- */
- public float floatValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the double value if this primitive value is of type double.
- * @return the double value if this primitive value is of type double.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type double.
- */
- public double doubleValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
+ throw new UnsupportedOperationException("this " + size() + "-byte primitive");
}
}
diff --git a/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java b/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
index db8901ea731..b6583adf559 100644
--- a/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
+++ b/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -24,15 +24,13 @@
*/
package java.lang;
-import java.lang.StackWalker.Option;
-import java.util.EnumSet;
-import java.util.Set;
-
-import static java.lang.StackWalker.ExtendedOption.*;
-
final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame {
private static Object[] EMPTY_ARRAY = new Object[0];
+ // These flags must match the values maintained in the VM
+ private static final int MODE_INTERPRETED = 0x01;
+ private static final int MODE_COMPILED = 0x02;
+
LiveStackFrameInfo(StackWalker walker) {
super(walker);
}
@@ -41,6 +39,7 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
private Object[] monitors = EMPTY_ARRAY;
private Object[] locals = EMPTY_ARRAY;
private Object[] operands = EMPTY_ARRAY;
+ private int mode = 0;
@Override
public Object[] getMonitors() {
@@ -57,51 +56,44 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
return operands;
}
+ @Override
+ public String toString() {
+ StringBuilder retVal = new StringBuilder(super.toString());
+ if (mode != 0) {
+ retVal.append("(");
+ if ((mode & MODE_INTERPRETED) == MODE_INTERPRETED) {
+ retVal.append(" interpreted ");
+ }
+ if ((mode & MODE_COMPILED) == MODE_COMPILED) {
+ retVal.append(" compiled ");
+ }
+ retVal.append(")");
+ }
+ return retVal.toString();
+ }
+
/*
- * Convert primitive value to {@code Primitive} object to represent
+ * Convert primitive value to {@code PrimitiveSlot} object to represent
* a local variable or an element on the operand stack of primitive type.
*/
- static PrimitiveValue asPrimitive(boolean value) {
- return new BooleanPrimitive(value);
+
+ static PrimitiveSlot asPrimitive(int value) {
+ return new PrimitiveSlot32(value);
}
- static PrimitiveValue asPrimitive(int value) {
- return new IntPrimitive(value);
+ static PrimitiveSlot asPrimitive(long value) {
+ return new PrimitiveSlot64(value);
}
- static PrimitiveValue asPrimitive(short value) {
- return new ShortPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(char value) {
- return new CharPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(byte value) {
- return new BytePrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(long value) {
- return new LongPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(float value) {
- return new FloatPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(double value) {
- return new DoublePrimitive(value);
- }
-
- private static class IntPrimitive extends PrimitiveValue {
+ private static class PrimitiveSlot32 extends PrimitiveSlot {
final int value;
- IntPrimitive(int value) {
+ PrimitiveSlot32(int value) {
this.value = value;
}
@Override
- public char type() {
- return 'I';
+ public int size() {
+ return 4;
}
@Override
@@ -115,103 +107,15 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
}
}
- private static class ShortPrimitive extends PrimitiveValue {
- final short value;
- ShortPrimitive(short value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'S';
- }
-
- @Override
- public short shortValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class BooleanPrimitive extends PrimitiveValue {
- final boolean value;
- BooleanPrimitive(boolean value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'Z';
- }
-
- @Override
- public boolean booleanValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class CharPrimitive extends PrimitiveValue {
- final char value;
- CharPrimitive(char value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'C';
- }
-
- @Override
- public char charValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class BytePrimitive extends PrimitiveValue {
- final byte value;
- BytePrimitive(byte value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'B';
- }
-
- @Override
- public byte byteValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class LongPrimitive extends PrimitiveValue {
+ private static class PrimitiveSlot64 extends PrimitiveSlot {
final long value;
- LongPrimitive(long value) {
+ PrimitiveSlot64(long value) {
this.value = value;
}
@Override
- public char type() {
- return 'J';
+ public int size() {
+ return 8;
}
@Override
@@ -224,48 +128,4 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
return String.valueOf(value);
}
}
-
- private static class FloatPrimitive extends PrimitiveValue {
- final float value;
- FloatPrimitive(float value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'F';
- }
-
- @Override
- public float floatValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class DoublePrimitive extends PrimitiveValue {
- final double value;
- DoublePrimitive(double value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'D';
- }
-
- @Override
- public double doubleValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
}
diff --git a/jdk/src/java.base/share/lib/security/default.policy b/jdk/src/java.base/share/lib/security/default.policy
index 75147a6ae14..36521f38e1d 100644
--- a/jdk/src/java.base/share/lib/security/default.policy
+++ b/jdk/src/java.base/share/lib/security/default.policy
@@ -215,3 +215,7 @@ grant {
permission java.lang.RuntimePermission "accessClassInPackage.com.sun.java.swing.plaf.*";
permission java.lang.RuntimePermission "accessClassInPackage.com.apple.*";
};
+
+grant codeBase "jrt:/jdk.vm.compiler" {
+ permission java.security.AllPermission;
+};
diff --git a/jdk/test/java/lang/StackWalker/CountLocalSlots.java b/jdk/test/java/lang/StackWalker/CountLocalSlots.java
deleted file mode 100644
index dfb1698d188..00000000000
--- a/jdk/test/java/lang/StackWalker/CountLocalSlots.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2016, 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 8147039
- * @summary Confirm locals[] always has expected length, even for "dead" locals
- * @modules java.base/java.lang:open
- * @compile LocalsAndOperands.java
- * @run testng/othervm -Xcomp CountLocalSlots
- */
-
-import org.testng.annotations.Test;
-import java.lang.StackWalker.StackFrame;
-
-public class CountLocalSlots {
- final static boolean debug = true;
-
- @Test(dataProvider = "provider", dataProviderClass = LocalsAndOperands.class)
- public void countLocalSlots(StackFrame... frames) {
- for (StackFrame frame : frames) {
- if (debug) {
- System.out.println("Running countLocalSlots");
- LocalsAndOperands.dumpStackWithLocals(frames);
- }
- // Confirm expected number of locals
- String methodName = frame.getMethodName();
- Integer expectedObj = (Integer) LocalsAndOperands.Tester.NUM_LOCALS.get(methodName);
- if (expectedObj == null) {
- if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
- throw new RuntimeException("No NUM_LOCALS entry for " +
- methodName + "(). Update test?");
- }
- Object[] locals = (Object[]) LocalsAndOperands.invokeGetLocals(frame);
- if (locals.length != expectedObj) {
- if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
- throw new RuntimeException(methodName + "(): number of locals (" +
- locals.length + ") did not match expected (" + expectedObj + ")");
- }
- }
- }
-}
diff --git a/jdk/test/java/lang/StackWalker/LocalsAndOperands.java b/jdk/test/java/lang/StackWalker/LocalsAndOperands.java
index ab07c7d9ad8..1b9d71b696b 100644
--- a/jdk/test/java/lang/StackWalker/LocalsAndOperands.java
+++ b/jdk/test/java/lang/StackWalker/LocalsAndOperands.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -23,33 +23,54 @@
/*
* @test
- * @bug 8020968 8147039
+ * @bug 8020968 8147039 8156073
* @summary Tests for locals and operands
* @modules java.base/java.lang:open
- * @run testng LocalsAndOperands
+ * @run testng/othervm -Xint -DtestUnused=true LocalsAndOperands
+ * @run testng/othervm -Xcomp LocalsAndOperands
+ * @run testng/othervm -Xcomp -XX:-TieredCompilation LocalsAndOperands
*/
import org.testng.annotations.*;
+import static org.testng.Assert.*;
import java.lang.StackWalker.StackFrame;
+import static java.lang.StackWalker.Option.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.stream.*;
public class LocalsAndOperands {
- static final boolean debug = true;
+ static final boolean debug = false;
+ static final boolean is32bit;
+ static final boolean testUnused;
static Class> liveStackFrameClass;
- static Class> primitiveValueClass;
+ static Class> primitiveSlotClass;
+ static Class> primitiveSlot32Class;
+ static Class> primitiveSlot64Class;
+
static StackWalker extendedWalker;
static Method getLocals;
static Method getOperands;
static Method getMonitors;
- static Method primitiveType;
+ static Method primitiveSize;
+ static Method primitiveLongValue;
+ static Method primitiveIntValue;
+ static Method getExtendedWalker;
+
+ private static final long LOWER_LONG_VAL = 4L; // Lower bits
+ private static final long UPPER_LONG_VAL = 0x123400000000L; // Upper bits
+ private static final long NEG_LONG_VAL = Long.MIN_VALUE;
+
+ private static final double LOWER_DOUBLE_VAL = Double.longBitsToDouble(0xABCDL);
+ private static final double UPPER_DOUBLE_VAL = Double.longBitsToDouble(0x432100000000L);
static {
try {
liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
- primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveValue");
+ primitiveSlotClass = Class.forName("java.lang.LiveStackFrame$PrimitiveSlot");
+ primitiveSlot32Class = Class.forName("java.lang.LiveStackFrameInfo$PrimitiveSlot32");
+ primitiveSlot64Class = Class.forName("java.lang.LiveStackFrameInfo$PrimitiveSlot64");
getLocals = liveStackFrameClass.getDeclaredMethod("getLocals");
getLocals.setAccessible(true);
@@ -60,12 +81,31 @@ public class LocalsAndOperands {
getMonitors = liveStackFrameClass.getDeclaredMethod("getMonitors");
getMonitors.setAccessible(true);
- primitiveType = primitiveValueClass.getDeclaredMethod("type");
- primitiveType.setAccessible(true);
+ primitiveSize = primitiveSlotClass.getDeclaredMethod("size");
+ primitiveSize.setAccessible(true);
- Method method = liveStackFrameClass.getMethod("getStackWalker");
- method.setAccessible(true);
- extendedWalker = (StackWalker) method.invoke(null);
+ primitiveLongValue = primitiveSlotClass.getDeclaredMethod("longValue");
+ primitiveLongValue.setAccessible(true);
+
+ primitiveIntValue = primitiveSlotClass.getDeclaredMethod("intValue");
+ primitiveIntValue.setAccessible(true);
+
+ getExtendedWalker = liveStackFrameClass.getMethod("getStackWalker", Set.class);
+ getExtendedWalker.setAccessible(true);
+ extendedWalker = (StackWalker) getExtendedWalker.invoke(null,
+ EnumSet.noneOf(StackWalker.Option.class));
+
+ String dataModel = System.getProperty("sun.arch.data.model");
+ if ("32".equals(dataModel)) {
+ is32bit = true;
+ } else if ("64".equals(dataModel)) {
+ is32bit= false;
+ } else {
+ throw new RuntimeException("Weird data model:" + dataModel);
+ }
+ System.out.println("VM bits: " + dataModel);
+
+ testUnused = System.getProperty("testUnused") != null;
} catch (Throwable t) { throw new RuntimeException(t); }
}
@@ -80,47 +120,17 @@ public class LocalsAndOperands {
* DataProviders *
*****************/
- /** Calls testLocals() and provides LiveStackFrames for testLocals* methods */
+ /** Calls KnownLocalsTester.testLocals* and provides LiveStackFrames */
@DataProvider
- public static StackFrame[][] provider() {
- return new StackFrame[][] {
- new Tester().testLocals()
- };
- }
-
- /**
- * Calls testLocalsKeepAlive() and provides LiveStackFrames for testLocals* methods.
- * Local variables in testLocalsKeepAlive() are ensured to not become dead.
- */
- @DataProvider
- public static StackFrame[][] keepAliveProvider() {
- return new StackFrame[][] {
- new Tester().testLocalsKeepAlive()
- };
- }
-
- /**
- * Provides StackFrames from a StackWalker without the LOCALS_AND_OPERANDS
- * option.
- */
- @DataProvider
- public static StackFrame[][] noLocalsProvider() {
- // Use default StackWalker
- return new StackFrame[][] {
- new Tester(StackWalker.getInstance(), true).testLocals()
- };
- }
-
- /**
- * Calls testLocals() and provides LiveStackFrames for *all* called methods,
- * including test infrastructure (jtreg, testng, etc)
- *
- */
- @DataProvider
- public static StackFrame[][] unfilteredProvider() {
- return new StackFrame[][] {
- new Tester(extendedWalker, false).testLocals()
- };
+ public static StackFrame[][] knownLocalsProvider() {
+ List