--- a/jdk/src/java.base/share/classes/java/lang/Thread.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Thread.java Sat May 14 09:11:07 2016 -0700
@@ -341,6 +341,45 @@
}
/**
+ * Indicates that the caller is momentarily unable to progress, until the
+ * occurrence of one or more actions on the part of other activities. By
+ * invoking this method within each iteration of a spin-wait loop construct,
+ * the calling thread indicates to the runtime that it is busy-waiting.
+ * The runtime may take action to improve the performance of invoking
+ * spin-wait loop constructions.
+ * <p>
+ * @apiNote
+ * As an example consider a method in a class that spins in a loop until
+ * some flag is set outside of that method. A call to the {@code onSpinWait}
+ * method should be placed inside the spin loop.
+ * <pre>{@code
+ * class EventHandler {
+ * volatile boolean eventNotificationNotReceived;
+ * void waitForEventAndHandleIt() {
+ * while ( eventNotificationNotReceived ) {
+ * java.lang.Thread.onSpinWait();
+ * }
+ * readAndProcessEvent();
+ * }
+ *
+ * void readAndProcessEvent() {
+ * // Read event from some source and process it
+ * . . .
+ * }
+ * }
+ * }</pre>
+ * <p>
+ * The code above would remain correct even if the {@code onSpinWait}
+ * method was not called at all. However on some architectures the Java
+ * Virtual Machine may issue the processor instructions to address such
+ * code patterns in a more beneficial way.
+ * <p>
+ * @since 9
+ */
+ @HotSpotIntrinsicCandidate
+ public static void onSpinWait() {}
+
+ /**
* Initializes a Thread with the current AccessControlContext.
* @see #init(ThreadGroup,Runnable,String,long,AccessControlContext,boolean)
*/
--- a/jdk/src/java.base/share/classes/java/lang/invoke/VarHandle.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/VarHandle.java Sat May 14 09:11:07 2016 -0700
@@ -26,6 +26,7 @@
package java.lang.invoke;
import jdk.internal.HotSpotIntrinsicCandidate;
+import jdk.internal.util.Preconditions;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
@@ -33,7 +34,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
@@ -1501,7 +1501,7 @@
}
static final BiFunction<String, List<Integer>, ArrayIndexOutOfBoundsException>
- AIOOBE_SUPPLIER = Objects.outOfBoundsExceptionFormatter(
+ AIOOBE_SUPPLIER = Preconditions.outOfBoundsExceptionFormatter(
new Function<String, ArrayIndexOutOfBoundsException>() {
@Override
public ArrayIndexOutOfBoundsException apply(String s) {
--- a/jdk/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template Sat May 14 09:11:07 2016 -0700
@@ -24,8 +24,10 @@
*/
package java.lang.invoke;
+import jdk.internal.util.Preconditions;
+import jdk.internal.vm.annotation.ForceInline;
+
import java.util.Objects;
-import jdk.internal.vm.annotation.ForceInline;
import static java.lang.invoke.MethodHandleStatics.UNSAFE;
@@ -447,7 +449,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.get$Type$Volatile(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
}
@ForceInline
@@ -458,7 +460,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
UNSAFE.put$Type$Volatile(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -470,7 +472,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.get$Type$Opaque(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
}
@ForceInline
@@ -481,7 +483,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
UNSAFE.put$Type$Opaque(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -493,7 +495,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.get$Type$Acquire(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
}
@ForceInline
@@ -504,7 +506,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
UNSAFE.put$Type$Release(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(value):value});
}
#if[CAS]
@@ -517,7 +519,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.compareAndSwap$Type$(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -530,7 +532,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.compareAndExchange$Type$Volatile(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -543,7 +545,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.compareAndExchange$Type$Acquire(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -556,7 +558,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.compareAndExchange$Type$Release(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -569,7 +571,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.weakCompareAndSwap$Type$(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -583,7 +585,7 @@
#end[Object]
// TODO defer to strong form until new Unsafe method is added
return UNSAFE.compareAndSwap$Type$(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -596,7 +598,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.weakCompareAndSwap$Type$Acquire(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -609,7 +611,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.weakCompareAndSwap$Type$Release(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(expected):expected},
{#if[Object]?handle.componentType.cast(value):value});
}
@@ -622,7 +624,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.getAndSet$Type$(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
{#if[Object]?handle.componentType.cast(value):value});
}
#end[CAS]
@@ -636,7 +638,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.getAndAdd$Type$(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
value);
}
@@ -648,7 +650,7 @@
$type$[] array = ($type$[]) oarray;
#end[Object]
return UNSAFE.getAndAdd$Type$(array,
- (((long) Objects.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+ (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
value) + value;
}
#end[AtomicAdd]
--- a/jdk/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template Sat May 14 09:11:07 2016 -0700
@@ -25,6 +25,7 @@
package java.lang.invoke;
import jdk.internal.misc.Unsafe;
+import jdk.internal.util.Preconditions;
import jdk.internal.vm.annotation.ForceInline;
import java.nio.ByteBuffer;
@@ -81,7 +82,7 @@
@ForceInline
static int index(byte[] ba, int index) {
- return Objects.checkIndex(index, ba.length - ALIGN, null);
+ return Preconditions.checkIndex(index, ba.length - ALIGN, null);
}
@ForceInline
@@ -307,14 +308,14 @@
@ForceInline
static int index(ByteBuffer bb, int index) {
- return Objects.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
+ return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
}
@ForceInline
static int indexRO(ByteBuffer bb, int index) {
if (UNSAFE.getBoolean(bb, BYTE_BUFFER_IS_READ_ONLY))
throw new ReadOnlyBufferException();
- return Objects.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
+ return Preconditions.checkIndex(index, UNSAFE.getInt(bb, BUFFER_LIMIT) - ALIGN, null);
}
@ForceInline
--- a/jdk/src/java.base/share/classes/java/util/Objects.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/util/Objects.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -25,10 +25,9 @@
package java.util;
-import jdk.internal.HotSpotIntrinsicCandidate;
+import jdk.internal.util.Preconditions;
+import jdk.internal.vm.annotation.ForceInline;
-import java.util.function.BiFunction;
-import java.util.function.Function;
import java.util.function.Supplier;
/**
@@ -349,172 +348,6 @@
}
/**
- * Maps out-of-bounds values to a runtime exception.
- *
- * @param checkKind the kind of bounds check, whose name may correspond
- * to the name of one of the range check methods, checkIndex,
- * checkFromToIndex, checkFromIndexSize
- * @param args the out-of-bounds arguments that failed the range check.
- * If the checkKind corresponds a the name of a range check method
- * then the bounds arguments are those that can be passed in order
- * to the method.
- * @param oobef the exception formatter that when applied with a checkKind
- * and a list out-of-bounds arguments returns a runtime exception.
- * If {@code null} then, it is as if an exception formatter was
- * supplied that returns {@link IndexOutOfBoundsException} for any
- * given arguments.
- * @return the runtime exception
- */
- private static RuntimeException outOfBounds(
- BiFunction<String, List<Integer>, ? extends RuntimeException> oobef,
- String checkKind,
- Integer... args) {
- List<Integer> largs = List.of(args);
- RuntimeException e = oobef == null
- ? null : oobef.apply(checkKind, largs);
- return e == null
- ? new IndexOutOfBoundsException(outOfBoundsMessage(checkKind, largs)) : e;
- }
-
- // Specific out-of-bounds exception producing methods that avoid
- // the varargs-based code in the critical methods there by reducing their
- // the byte code size, and therefore less likely to peturb inlining
-
- private static RuntimeException outOfBoundsCheckIndex(
- BiFunction<String, List<Integer>, ? extends RuntimeException> oobe,
- int index, int length) {
- return outOfBounds(oobe, "checkIndex", index, length);
- }
-
- private static RuntimeException outOfBoundsCheckFromToIndex(
- BiFunction<String, List<Integer>, ? extends RuntimeException> oobe,
- int fromIndex, int toIndex, int length) {
- return outOfBounds(oobe, "checkFromToIndex", fromIndex, toIndex, length);
- }
-
- private static RuntimeException outOfBoundsCheckFromIndexSize(
- BiFunction<String, List<Integer>, ? extends RuntimeException> oobe,
- int fromIndex, int size, int length) {
- return outOfBounds(oobe, "checkFromIndexSize", fromIndex, size, length);
- }
-
- /**
- * Returns an out-of-bounds exception formatter from an given exception
- * factory. The exception formatter is a function that formats an
- * out-of-bounds message from its arguments and applies that message to the
- * given exception factory to produce and relay an exception.
- *
- * <p>The exception formatter accepts two arguments: a {@code String}
- * describing the out-of-bounds range check that failed, referred to as the
- * <em>check kind</em>; and a {@code List<Integer>} containing the
- * out-of-bound integer values that failed the check. The list of
- * out-of-bound values is not modified.
- *
- * <p>Three check kinds are supported {@code checkIndex},
- * {@code checkFromToIndex} and {@code checkFromIndexSize} corresponding
- * respectively to the specified application of an exception formatter as an
- * argument to the out-of-bounds range check methods
- * {@link #checkIndex(int, int, BiFunction) checkIndex},
- * {@link #checkFromToIndex(int, int, int, BiFunction) checkFromToIndex}, and
- * {@link #checkFromIndexSize(int, int, int, BiFunction) checkFromIndexSize}.
- * Thus a supported check kind corresponds to a method name and the
- * out-of-bound integer values correspond to method argument values, in
- * order, preceding the exception formatter argument (similar in many
- * respects to the form of arguments required for a reflective invocation of
- * such a range check method).
- *
- * <p>Formatter arguments conforming to such supported check kinds will
- * produce specific exception messages describing failed out-of-bounds
- * checks. Otherwise, more generic exception messages will be produced in
- * any of the following cases: the check kind is supported but fewer
- * or more out-of-bounds values are supplied, the check kind is not
- * supported, the check kind is {@code null}, or the list of out-of-bound
- * values is {@code null}.
- *
- * @apiNote
- * This method produces an out-of-bounds exception formatter that can be
- * passed as an argument to any of the supported out-of-bounds range check
- * methods declared by {@code Objects}. For example, a formatter producing
- * an {@code ArrayIndexOutOfBoundsException} may be produced and stored on a
- * {@code static final} field as follows:
- * <pre>{@code
- * static final
- * BiFunction<String, List<Integer>, ArrayIndexOutOfBoundsException> AIOOBEF =
- * outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new);
- * }</pre>
- * The formatter instance {@code AIOOBEF} may be passed as an argument to an
- * out-of-bounds range check method, such as checking if an {@code index}
- * is within the bounds of a {@code limit}:
- * <pre>{@code
- * checkIndex(index, limit, AIOOBEF);
- * }</pre>
- * If the bounds check fails then the range check method will throw an
- * {@code ArrayIndexOutOfBoundsException} with an appropriate exception
- * message that is a produced from {@code AIOOBEF} as follows:
- * <pre>{@code
- * AIOOBEF.apply("checkIndex", List.of(index, limit));
- * }</pre>
- *
- * @param f the exception factory, that produces an exception from a message
- * where the message is produced and formatted by the returned
- * exception formatter. If this factory is stateless and side-effect
- * free then so is the returned formatter.
- * Exceptions thrown by the factory are relayed to the caller
- * of the returned formatter.
- * @param <X> the type of runtime exception to be returned by the given
- * exception factory and relayed by the exception formatter
- * @return the out-of-bounds exception formatter
- */
- public static <X extends RuntimeException>
- BiFunction<String, List<Integer>, X> outOfBoundsExceptionFormatter(Function<String, X> f) {
- // Use anonymous class to avoid bootstrap issues if this method is
- // used early in startup
- return new BiFunction<String, List<Integer>, X>() {
- @Override
- public X apply(String checkKind, List<Integer> args) {
- return f.apply(outOfBoundsMessage(checkKind, args));
- }
- };
- }
-
- private static String outOfBoundsMessage(String checkKind, List<Integer> args) {
- if (checkKind == null && args == null) {
- return String.format("Range check failed");
- } else if (checkKind == null) {
- return String.format("Range check failed: %s", args);
- } else if (args == null) {
- return String.format("Range check failed: %s", checkKind);
- }
-
- int argSize = 0;
- switch (checkKind) {
- case "checkIndex":
- argSize = 2;
- break;
- case "checkFromToIndex":
- case "checkFromIndexSize":
- argSize = 3;
- break;
- default:
- }
-
- // Switch to default if fewer or more arguments than required are supplied
- switch ((args.size() != argSize) ? "" : checkKind) {
- case "checkIndex":
- return String.format("Index %d out-of-bounds for length %d",
- args.get(0), args.get(1));
- case "checkFromToIndex":
- return String.format("Range [%d, %d) out-of-bounds for length %d",
- args.get(0), args.get(1), args.get(2));
- case "checkFromIndexSize":
- return String.format("Range [%d, %<d + %d) out-of-bounds for length %d",
- args.get(0), args.get(1), args.get(2));
- default:
- return String.format("Range check failed: %s %s", checkKind, args);
- }
- }
-
- /**
* Checks if the {@code index} is within the bounds of the range from
* {@code 0} (inclusive) to {@code length} (exclusive).
*
@@ -526,72 +359,16 @@
* <li>{@code length < 0}, which is implied from the former inequalities</li>
* </ul>
*
- * <p>This method behaves as if {@link #checkIndex(int, int, BiFunction)}
- * was called with same out-of-bounds arguments and an exception formatter
- * argument produced from an invocation of
- * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} (though it may
- * be more efficient).
- *
* @param index the index
* @param length the upper-bound (exclusive) of the range
* @return {@code index} if it is within bounds of the range
* @throws IndexOutOfBoundsException if the {@code index} is out-of-bounds
* @since 9
*/
+ @ForceInline
public static
int checkIndex(int index, int length) {
- return checkIndex(index, length, null);
- }
-
- /**
- * Checks if the {@code index} is within the bounds of the range from
- * {@code 0} (inclusive) to {@code length} (exclusive).
- *
- * <p>The {@code index} is defined to be out-of-bounds if any of the
- * following inequalities is true:
- * <ul>
- * <li>{@code index < 0}</li>
- * <li>{@code index >= length}</li>
- * <li>{@code length < 0}, which is implied from the former inequalities</li>
- * </ul>
- *
- * <p>If the {@code index} is out-of-bounds, then a runtime exception is
- * thrown that is the result of applying the following arguments to the
- * exception formatter: the name of this method, {@code checkIndex};
- * and an unmodifiable list integers whose values are, in order, the
- * out-of-bounds arguments {@code index} and {@code length}.
- *
- * @param <X> the type of runtime exception to throw if the arguments are
- * out-of-bounds
- * @param index the index
- * @param length the upper-bound (exclusive) of the range
- * @param oobef the exception formatter that when applied with this
- * method name and out-of-bounds arguments returns a runtime
- * exception. If {@code null} or returns {@code null} then, it is as
- * if an exception formatter produced from an invocation of
- * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} is used
- * instead (though it may be more efficient).
- * Exceptions thrown by the formatter are relayed to the caller.
- * @return {@code index} if it is within bounds of the range
- * @throws X if the {@code index} is out-of-bounds and the exception
- * formatter is non-{@code null}
- * @throws IndexOutOfBoundsException if the {@code index} is out-of-bounds
- * and the exception formatter is {@code null}
- * @since 9
- *
- * @implNote
- * This method is made intrinsic in optimizing compilers to guide them to
- * perform unsigned comparisons of the index and length when it is known the
- * length is a non-negative value (such as that of an array length or from
- * the upper bound of a loop)
- */
- @HotSpotIntrinsicCandidate
- public static <X extends RuntimeException>
- int checkIndex(int index, int length,
- BiFunction<String, List<Integer>, X> oobef) {
- if (index < 0 || index >= length)
- throw outOfBoundsCheckIndex(oobef, index, length);
- return index;
+ return Preconditions.checkIndex(index, length, null);
}
/**
@@ -608,12 +385,6 @@
* <li>{@code length < 0}, which is implied from the former inequalities</li>
* </ul>
*
- * <p>This method behaves as if {@link #checkFromToIndex(int, int, int, BiFunction)}
- * was called with same out-of-bounds arguments and an exception formatter
- * argument produced from an invocation of
- * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} (though it may
- * be more efficient).
- *
* @param fromIndex the lower-bound (inclusive) of the sub-range
* @param toIndex the upper-bound (exclusive) of the sub-range
* @param length the upper-bound (exclusive) the range
@@ -623,54 +394,7 @@
*/
public static
int checkFromToIndex(int fromIndex, int toIndex, int length) {
- return checkFromToIndex(fromIndex, toIndex, length, null);
- }
-
- /**
- * Checks if the sub-range from {@code fromIndex} (inclusive) to
- * {@code toIndex} (exclusive) is within the bounds of range from {@code 0}
- * (inclusive) to {@code length} (exclusive).
- *
- * <p>The sub-range is defined to be out-of-bounds if any of the following
- * inequalities is true:
- * <ul>
- * <li>{@code fromIndex < 0}</li>
- * <li>{@code fromIndex > toIndex}</li>
- * <li>{@code toIndex > length}</li>
- * <li>{@code length < 0}, which is implied from the former inequalities</li>
- * </ul>
- *
- * <p>If the sub-range is out-of-bounds, then a runtime exception is
- * thrown that is the result of applying the following arguments to the
- * exception formatter: the name of this method, {@code checkFromToIndex};
- * and an unmodifiable list integers whose values are, in order, the
- * out-of-bounds arguments {@code fromIndex}, {@code toIndex}, and {@code length}.
- *
- * @param <X> the type of runtime exception to throw if the arguments are
- * out-of-bounds
- * @param fromIndex the lower-bound (inclusive) of the sub-range
- * @param toIndex the upper-bound (exclusive) of the sub-range
- * @param length the upper-bound (exclusive) the range
- * @param oobef the exception formatter that when applied with this
- * method name and out-of-bounds arguments returns a runtime
- * exception. If {@code null} or returns {@code null} then, it is as
- * if an exception formatter produced from an invocation of
- * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} is used
- * instead (though it may be more efficient).
- * Exceptions thrown by the formatter are relayed to the caller.
- * @return {@code fromIndex} if the sub-range within bounds of the range
- * @throws X if the sub-range is out-of-bounds and the exception factory
- * function is non-{@code null}
- * @throws IndexOutOfBoundsException if the sub-range is out-of-bounds and
- * the exception factory function is {@code null}
- * @since 9
- */
- public static <X extends RuntimeException>
- int checkFromToIndex(int fromIndex, int toIndex, int length,
- BiFunction<String, List<Integer>, X> oobef) {
- if (fromIndex < 0 || fromIndex > toIndex || toIndex > length)
- throw outOfBoundsCheckFromToIndex(oobef, fromIndex, toIndex, length);
- return fromIndex;
+ return Preconditions.checkFromToIndex(fromIndex, toIndex, length, null);
}
/**
@@ -687,12 +411,6 @@
* <li>{@code length < 0}, which is implied from the former inequalities</li>
* </ul>
*
- * <p>This method behaves as if {@link #checkFromIndexSize(int, int, int, BiFunction)}
- * was called with same out-of-bounds arguments and an exception formatter
- * argument produced from an invocation of
- * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} (though it may
- * be more efficient).
- *
* @param fromIndex the lower-bound (inclusive) of the sub-interval
* @param size the size of the sub-range
* @param length the upper-bound (exclusive) of the range
@@ -702,54 +420,7 @@
*/
public static
int checkFromIndexSize(int fromIndex, int size, int length) {
- return checkFromIndexSize(fromIndex, size, length, null);
+ return Preconditions.checkFromIndexSize(fromIndex, size, length, null);
}
- /**
- * Checks if the sub-range from {@code fromIndex} (inclusive) to
- * {@code fromIndex + size} (exclusive) is within the bounds of range from
- * {@code 0} (inclusive) to {@code length} (exclusive).
- *
- * <p>The sub-range is defined to be out-of-bounds if any of the following
- * inequalities is true:
- * <ul>
- * <li>{@code fromIndex < 0}</li>
- * <li>{@code size < 0}</li>
- * <li>{@code fromIndex + size > length}, taking into account integer overflow</li>
- * <li>{@code length < 0}, which is implied from the former inequalities</li>
- * </ul>
- *
- * <p>If the sub-range is out-of-bounds, then a runtime exception is
- * thrown that is the result of applying the following arguments to the
- * exception formatter: the name of this method, {@code checkFromIndexSize};
- * and an unmodifiable list integers whose values are, in order, the
- * out-of-bounds arguments {@code fromIndex}, {@code size}, and
- * {@code length}.
- *
- * @param <X> the type of runtime exception to throw if the arguments are
- * out-of-bounds
- * @param fromIndex the lower-bound (inclusive) of the sub-interval
- * @param size the size of the sub-range
- * @param length the upper-bound (exclusive) of the range
- * @param oobef the exception formatter that when applied with this
- * method name and out-of-bounds arguments returns a runtime
- * exception. If {@code null} or returns {@code null} then, it is as
- * if an exception formatter produced from an invocation of
- * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} is used
- * instead (though it may be more efficient).
- * Exceptions thrown by the formatter are relayed to the caller.
- * @return {@code fromIndex} if the sub-range within bounds of the range
- * @throws X if the sub-range is out-of-bounds and the exception factory
- * function is non-{@code null}
- * @throws IndexOutOfBoundsException if the sub-range is out-of-bounds and
- * the exception factory function is {@code null}
- * @since 9
- */
- public static <X extends RuntimeException>
- int checkFromIndexSize(int fromIndex, int size, int length,
- BiFunction<String, List<Integer>, X> oobef) {
- if ((length | fromIndex | size) < 0 || size > length - fromIndex)
- throw outOfBoundsCheckFromIndexSize(oobef, fromIndex, size, length);
- return fromIndex;
- }
}
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java Sat May 14 09:11:07 2016 -0700
@@ -33,6 +33,7 @@
import jdk.internal.misc.VM;
import jdk.internal.HotSpotIntrinsicCandidate;
+import jdk.internal.vm.annotation.ForceInline;
/**
@@ -209,46 +210,103 @@
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native boolean getBoolean(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putBoolean(Object o, long offset, boolean x);
+
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native byte getByte(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putByte(Object o, long offset, byte x);
+
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native short getShort(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putShort(Object o, long offset, short x);
+
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native char getChar(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putChar(Object o, long offset, char x);
+
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native long getLong(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putLong(Object o, long offset, long x);
+
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native float getFloat(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putFloat(Object o, long offset, float x);
+
/** @see #getInt(Object, long) */
@HotSpotIntrinsicCandidate
public native double getDouble(Object o, long offset);
+
/** @see #putInt(Object, long, int) */
@HotSpotIntrinsicCandidate
public native void putDouble(Object o, long offset, double x);
+ /**
+ * Fetches a native pointer from a given memory address. If the address is
+ * zero, or does not point into a block obtained from {@link
+ * #allocateMemory}, the results are undefined.
+ *
+ * <p>If the native pointer is less than 64 bits wide, it is extended as
+ * an unsigned number to a Java long. The pointer may be indexed by any
+ * given byte offset, simply by adding that offset (as a simple integer) to
+ * the long representing the pointer. The number of bytes actually read
+ * from the target address may be determined by consulting {@link
+ * #addressSize}.
+ *
+ * @see #allocateMemory
+ * @see #getInt(Object, long)
+ */
+ @ForceInline
+ public long getAddress(Object o, long offset) {
+ if (ADDRESS_SIZE == 4) {
+ return Integer.toUnsignedLong(getInt(o, offset));
+ } else {
+ return getLong(o, offset);
+ }
+ }
+
+ /**
+ * Stores a native pointer into a given memory address. If the address is
+ * zero, or does not point into a block obtained from {@link
+ * #allocateMemory}, the results are undefined.
+ *
+ * <p>The number of bytes actually written at the target address may be
+ * determined by consulting {@link #addressSize}.
+ *
+ * @see #allocateMemory
+ * @see #putInt(Object, long, int)
+ */
+ @ForceInline
+ public void putAddress(Object o, long offset, long x) {
+ if (ADDRESS_SIZE == 4) {
+ putInt(o, offset, (int)x);
+ } else {
+ putLong(o, offset, x);
+ }
+ }
+
// These read VM internal data.
/**
@@ -287,8 +345,10 @@
*
* @see #allocateMemory
*/
- @HotSpotIntrinsicCandidate
- public native byte getByte(long address);
+ @ForceInline
+ public byte getByte(long address) {
+ return getByte(null, address);
+ }
/**
* Stores a value into a given memory address. If the address is zero, or
@@ -297,75 +357,94 @@
*
* @see #getByte(long)
*/
- @HotSpotIntrinsicCandidate
- public native void putByte(long address, byte x);
+ @ForceInline
+ public void putByte(long address, byte x) {
+ putByte(null, address, x);
+ }
+
+ /** @see #getByte(long) */
+ @ForceInline
+ public short getShort(long address) {
+ return getShort(null, address);
+ }
+
+ /** @see #putByte(long, byte) */
+ @ForceInline
+ public void putShort(long address, short x) {
+ putShort(null, address, x);
+ }
+
+ /** @see #getByte(long) */
+ @ForceInline
+ public char getChar(long address) {
+ return getChar(null, address);
+ }
+
+ /** @see #putByte(long, byte) */
+ @ForceInline
+ public void putChar(long address, char x) {
+ putChar(null, address, x);
+ }
+
+ /** @see #getByte(long) */
+ @ForceInline
+ public int getInt(long address) {
+ return getInt(null, address);
+ }
+
+ /** @see #putByte(long, byte) */
+ @ForceInline
+ public void putInt(long address, int x) {
+ putInt(null, address, x);
+ }
/** @see #getByte(long) */
- @HotSpotIntrinsicCandidate
- public native short getShort(long address);
- /** @see #putByte(long, byte) */
- @HotSpotIntrinsicCandidate
- public native void putShort(long address, short x);
- /** @see #getByte(long) */
- @HotSpotIntrinsicCandidate
- public native char getChar(long address);
- /** @see #putByte(long, byte) */
- @HotSpotIntrinsicCandidate
- public native void putChar(long address, char x);
- /** @see #getByte(long) */
- @HotSpotIntrinsicCandidate
- public native int getInt(long address);
+ @ForceInline
+ public long getLong(long address) {
+ return getLong(null, address);
+ }
+
/** @see #putByte(long, byte) */
- @HotSpotIntrinsicCandidate
- public native void putInt(long address, int x);
- /** @see #getByte(long) */
- @HotSpotIntrinsicCandidate
- public native long getLong(long address);
- /** @see #putByte(long, byte) */
- @HotSpotIntrinsicCandidate
- public native void putLong(long address, long x);
+ @ForceInline
+ public void putLong(long address, long x) {
+ putLong(null, address, x);
+ }
+
/** @see #getByte(long) */
- @HotSpotIntrinsicCandidate
- public native float getFloat(long address);
- /** @see #putByte(long, byte) */
- @HotSpotIntrinsicCandidate
- public native void putFloat(long address, float x);
- /** @see #getByte(long) */
- @HotSpotIntrinsicCandidate
- public native double getDouble(long address);
+ @ForceInline
+ public float getFloat(long address) {
+ return getFloat(null, address);
+ }
+
/** @see #putByte(long, byte) */
- @HotSpotIntrinsicCandidate
- public native void putDouble(long address, double x);
+ @ForceInline
+ public void putFloat(long address, float x) {
+ putFloat(null, address, x);
+ }
+
+ /** @see #getByte(long) */
+ @ForceInline
+ public double getDouble(long address) {
+ return getDouble(null, address);
+ }
- /**
- * Fetches a native pointer from a given memory address. If the address is
- * zero, or does not point into a block obtained from {@link
- * #allocateMemory}, the results are undefined.
- *
- * <p>If the native pointer is less than 64 bits wide, it is extended as
- * an unsigned number to a Java long. The pointer may be indexed by any
- * given byte offset, simply by adding that offset (as a simple integer) to
- * the long representing the pointer. The number of bytes actually read
- * from the target address may be determined by consulting {@link
- * #addressSize}.
- *
- * @see #allocateMemory
- */
- @HotSpotIntrinsicCandidate
- public native long getAddress(long address);
+ /** @see #putByte(long, byte) */
+ @ForceInline
+ public void putDouble(long address, double x) {
+ putDouble(null, address, x);
+ }
- /**
- * Stores a native pointer into a given memory address. If the address is
- * zero, or does not point into a block obtained from {@link
- * #allocateMemory}, the results are undefined.
- *
- * <p>The number of bytes actually written at the target address may be
- * determined by consulting {@link #addressSize}.
- *
- * @see #getAddress(long)
- */
- @HotSpotIntrinsicCandidate
- public native void putAddress(long address, long x);
+ /** @see #getAddress(Object, long) */
+ @ForceInline
+ public long getAddress(long address) {
+ return getAddress(null, address);
+ }
+
+ /** @see #putAddress(Object, long, long) */
+ @ForceInline
+ public void putAddress(long address, long x) {
+ putAddress(null, address, x);
+ }
@@ -1271,6 +1350,13 @@
return compareAndSwapObject(o, offset, expected, x);
}
+ @HotSpotIntrinsicCandidate
+ public final boolean weakCompareAndSwapObjectVolatile(Object o, long offset,
+ Object expected,
+ Object x) {
+ return compareAndSwapObject(o, offset, expected, x);
+ }
+
/**
* Atomically updates Java variable to {@code x} if it is currently
* holding {@code expected}.
@@ -1325,6 +1411,13 @@
return compareAndSwapInt(o, offset, expected, x);
}
+ @HotSpotIntrinsicCandidate
+ public final boolean weakCompareAndSwapIntVolatile(Object o, long offset,
+ int expected,
+ int x) {
+ return compareAndSwapInt(o, offset, expected, x);
+ }
+
/**
* Atomically updates Java variable to {@code x} if it is currently
* holding {@code expected}.
@@ -1379,6 +1472,13 @@
return compareAndSwapLong(o, offset, expected, x);
}
+ @HotSpotIntrinsicCandidate
+ public final boolean weakCompareAndSwapLongVolatile(Object o, long offset,
+ long expected,
+ long x) {
+ return compareAndSwapLong(o, offset, expected, x);
+ }
+
/**
* Fetches a reference value from a given Java variable, with volatile
* load semantics. Otherwise identical to {@link #getObject(Object, long)}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/util/Preconditions.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,346 @@
+/*
+ * 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. 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.
+ */
+package jdk.internal.util;
+
+import jdk.internal.HotSpotIntrinsicCandidate;
+
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+/**
+ * Utility methods to check if state or arguments are correct.
+ *
+ */
+public class Preconditions {
+
+ /**
+ * Maps out-of-bounds values to a runtime exception.
+ *
+ * @param checkKind the kind of bounds check, whose name may correspond
+ * to the name of one of the range check methods, checkIndex,
+ * checkFromToIndex, checkFromIndexSize
+ * @param args the out-of-bounds arguments that failed the range check.
+ * If the checkKind corresponds a the name of a range check method
+ * then the bounds arguments are those that can be passed in order
+ * to the method.
+ * @param oobef the exception formatter that when applied with a checkKind
+ * and a list out-of-bounds arguments returns a runtime exception.
+ * If {@code null} then, it is as if an exception formatter was
+ * supplied that returns {@link IndexOutOfBoundsException} for any
+ * given arguments.
+ * @return the runtime exception
+ */
+ private static RuntimeException outOfBounds(
+ BiFunction<String, List<Integer>, ? extends RuntimeException> oobef,
+ String checkKind,
+ Integer... args) {
+ List<Integer> largs = List.of(args);
+ RuntimeException e = oobef == null
+ ? null : oobef.apply(checkKind, largs);
+ return e == null
+ ? new IndexOutOfBoundsException(outOfBoundsMessage(checkKind, largs)) : e;
+ }
+
+ private static RuntimeException outOfBoundsCheckIndex(
+ BiFunction<String, List<Integer>, ? extends RuntimeException> oobe,
+ int index, int length) {
+ return outOfBounds(oobe, "checkIndex", index, length);
+ }
+
+ private static RuntimeException outOfBoundsCheckFromToIndex(
+ BiFunction<String, List<Integer>, ? extends RuntimeException> oobe,
+ int fromIndex, int toIndex, int length) {
+ return outOfBounds(oobe, "checkFromToIndex", fromIndex, toIndex, length);
+ }
+
+ private static RuntimeException outOfBoundsCheckFromIndexSize(
+ BiFunction<String, List<Integer>, ? extends RuntimeException> oobe,
+ int fromIndex, int size, int length) {
+ return outOfBounds(oobe, "checkFromIndexSize", fromIndex, size, length);
+ }
+
+ /**
+ * Returns an out-of-bounds exception formatter from an given exception
+ * factory. The exception formatter is a function that formats an
+ * out-of-bounds message from its arguments and applies that message to the
+ * given exception factory to produce and relay an exception.
+ *
+ * <p>The exception formatter accepts two arguments: a {@code String}
+ * describing the out-of-bounds range check that failed, referred to as the
+ * <em>check kind</em>; and a {@code List<Integer>} containing the
+ * out-of-bound integer values that failed the check. The list of
+ * out-of-bound values is not modified.
+ *
+ * <p>Three check kinds are supported {@code checkIndex},
+ * {@code checkFromToIndex} and {@code checkFromIndexSize} corresponding
+ * respectively to the specified application of an exception formatter as an
+ * argument to the out-of-bounds range check methods
+ * {@link #checkIndex(int, int, BiFunction) checkIndex},
+ * {@link #checkFromToIndex(int, int, int, BiFunction) checkFromToIndex}, and
+ * {@link #checkFromIndexSize(int, int, int, BiFunction) checkFromIndexSize}.
+ * Thus a supported check kind corresponds to a method name and the
+ * out-of-bound integer values correspond to method argument values, in
+ * order, preceding the exception formatter argument (similar in many
+ * respects to the form of arguments required for a reflective invocation of
+ * such a range check method).
+ *
+ * <p>Formatter arguments conforming to such supported check kinds will
+ * produce specific exception messages describing failed out-of-bounds
+ * checks. Otherwise, more generic exception messages will be produced in
+ * any of the following cases: the check kind is supported but fewer
+ * or more out-of-bounds values are supplied, the check kind is not
+ * supported, the check kind is {@code null}, or the list of out-of-bound
+ * values is {@code null}.
+ *
+ * @apiNote
+ * This method produces an out-of-bounds exception formatter that can be
+ * passed as an argument to any of the supported out-of-bounds range check
+ * methods declared by {@code Objects}. For example, a formatter producing
+ * an {@code ArrayIndexOutOfBoundsException} may be produced and stored on a
+ * {@code static final} field as follows:
+ * <pre>{@code
+ * static final
+ * BiFunction<String, List<Integer>, ArrayIndexOutOfBoundsException> AIOOBEF =
+ * outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new);
+ * }</pre>
+ * The formatter instance {@code AIOOBEF} may be passed as an argument to an
+ * out-of-bounds range check method, such as checking if an {@code index}
+ * is within the bounds of a {@code limit}:
+ * <pre>{@code
+ * checkIndex(index, limit, AIOOBEF);
+ * }</pre>
+ * If the bounds check fails then the range check method will throw an
+ * {@code ArrayIndexOutOfBoundsException} with an appropriate exception
+ * message that is a produced from {@code AIOOBEF} as follows:
+ * <pre>{@code
+ * AIOOBEF.apply("checkIndex", List.of(index, limit));
+ * }</pre>
+ *
+ * @param f the exception factory, that produces an exception from a message
+ * where the message is produced and formatted by the returned
+ * exception formatter. If this factory is stateless and side-effect
+ * free then so is the returned formatter.
+ * Exceptions thrown by the factory are relayed to the caller
+ * of the returned formatter.
+ * @param <X> the type of runtime exception to be returned by the given
+ * exception factory and relayed by the exception formatter
+ * @return the out-of-bounds exception formatter
+ */
+ public static <X extends RuntimeException>
+ BiFunction<String, List<Integer>, X> outOfBoundsExceptionFormatter(Function<String, X> f) {
+ // Use anonymous class to avoid bootstrap issues if this method is
+ // used early in startup
+ return new BiFunction<String, List<Integer>, X>() {
+ @Override
+ public X apply(String checkKind, List<Integer> args) {
+ return f.apply(outOfBoundsMessage(checkKind, args));
+ }
+ };
+ }
+
+ private static String outOfBoundsMessage(String checkKind, List<Integer> args) {
+ if (checkKind == null && args == null) {
+ return String.format("Range check failed");
+ } else if (checkKind == null) {
+ return String.format("Range check failed: %s", args);
+ } else if (args == null) {
+ return String.format("Range check failed: %s", checkKind);
+ }
+
+ int argSize = 0;
+ switch (checkKind) {
+ case "checkIndex":
+ argSize = 2;
+ break;
+ case "checkFromToIndex":
+ case "checkFromIndexSize":
+ argSize = 3;
+ break;
+ default:
+ }
+
+ // Switch to default if fewer or more arguments than required are supplied
+ switch ((args.size() != argSize) ? "" : checkKind) {
+ case "checkIndex":
+ return String.format("Index %d out-of-bounds for length %d",
+ args.get(0), args.get(1));
+ case "checkFromToIndex":
+ return String.format("Range [%d, %d) out-of-bounds for length %d",
+ args.get(0), args.get(1), args.get(2));
+ case "checkFromIndexSize":
+ return String.format("Range [%d, %<d + %d) out-of-bounds for length %d",
+ args.get(0), args.get(1), args.get(2));
+ default:
+ return String.format("Range check failed: %s %s", checkKind, args);
+ }
+ }
+
+ /**
+ * Checks if the {@code index} is within the bounds of the range from
+ * {@code 0} (inclusive) to {@code length} (exclusive).
+ *
+ * <p>The {@code index} is defined to be out-of-bounds if any of the
+ * following inequalities is true:
+ * <ul>
+ * <li>{@code index < 0}</li>
+ * <li>{@code index >= length}</li>
+ * <li>{@code length < 0}, which is implied from the former inequalities</li>
+ * </ul>
+ *
+ * <p>If the {@code index} is out-of-bounds, then a runtime exception is
+ * thrown that is the result of applying the following arguments to the
+ * exception formatter: the name of this method, {@code checkIndex};
+ * and an unmodifiable list integers whose values are, in order, the
+ * out-of-bounds arguments {@code index} and {@code length}.
+ *
+ * @param <X> the type of runtime exception to throw if the arguments are
+ * out-of-bounds
+ * @param index the index
+ * @param length the upper-bound (exclusive) of the range
+ * @param oobef the exception formatter that when applied with this
+ * method name and out-of-bounds arguments returns a runtime
+ * exception. If {@code null} or returns {@code null} then, it is as
+ * if an exception formatter produced from an invocation of
+ * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} is used
+ * instead (though it may be more efficient).
+ * Exceptions thrown by the formatter are relayed to the caller.
+ * @return {@code index} if it is within bounds of the range
+ * @throws X if the {@code index} is out-of-bounds and the exception
+ * formatter is non-{@code null}
+ * @throws IndexOutOfBoundsException if the {@code index} is out-of-bounds
+ * and the exception formatter is {@code null}
+ * @since 9
+ *
+ * @implNote
+ * This method is made intrinsic in optimizing compilers to guide them to
+ * perform unsigned comparisons of the index and length when it is known the
+ * length is a non-negative value (such as that of an array length or from
+ * the upper bound of a loop)
+ */
+ @HotSpotIntrinsicCandidate
+ public static <X extends RuntimeException>
+ int checkIndex(int index, int length,
+ BiFunction<String, List<Integer>, X> oobef) {
+ if (index < 0 || index >= length)
+ throw outOfBoundsCheckIndex(oobef, index, length);
+ return index;
+ }
+
+ /**
+ * Checks if the sub-range from {@code fromIndex} (inclusive) to
+ * {@code toIndex} (exclusive) is within the bounds of range from {@code 0}
+ * (inclusive) to {@code length} (exclusive).
+ *
+ * <p>The sub-range is defined to be out-of-bounds if any of the following
+ * inequalities is true:
+ * <ul>
+ * <li>{@code fromIndex < 0}</li>
+ * <li>{@code fromIndex > toIndex}</li>
+ * <li>{@code toIndex > length}</li>
+ * <li>{@code length < 0}, which is implied from the former inequalities</li>
+ * </ul>
+ *
+ * <p>If the sub-range is out-of-bounds, then a runtime exception is
+ * thrown that is the result of applying the following arguments to the
+ * exception formatter: the name of this method, {@code checkFromToIndex};
+ * and an unmodifiable list integers whose values are, in order, the
+ * out-of-bounds arguments {@code fromIndex}, {@code toIndex}, and {@code length}.
+ *
+ * @param <X> the type of runtime exception to throw if the arguments are
+ * out-of-bounds
+ * @param fromIndex the lower-bound (inclusive) of the sub-range
+ * @param toIndex the upper-bound (exclusive) of the sub-range
+ * @param length the upper-bound (exclusive) the range
+ * @param oobef the exception formatter that when applied with this
+ * method name and out-of-bounds arguments returns a runtime
+ * exception. If {@code null} or returns {@code null} then, it is as
+ * if an exception formatter produced from an invocation of
+ * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} is used
+ * instead (though it may be more efficient).
+ * Exceptions thrown by the formatter are relayed to the caller.
+ * @return {@code fromIndex} if the sub-range within bounds of the range
+ * @throws X if the sub-range is out-of-bounds and the exception factory
+ * function is non-{@code null}
+ * @throws IndexOutOfBoundsException if the sub-range is out-of-bounds and
+ * the exception factory function is {@code null}
+ * @since 9
+ */
+ public static <X extends RuntimeException>
+ int checkFromToIndex(int fromIndex, int toIndex, int length,
+ BiFunction<String, List<Integer>, X> oobef) {
+ if (fromIndex < 0 || fromIndex > toIndex || toIndex > length)
+ throw outOfBoundsCheckFromToIndex(oobef, fromIndex, toIndex, length);
+ return fromIndex;
+ }
+
+ /**
+ * Checks if the sub-range from {@code fromIndex} (inclusive) to
+ * {@code fromIndex + size} (exclusive) is within the bounds of range from
+ * {@code 0} (inclusive) to {@code length} (exclusive).
+ *
+ * <p>The sub-range is defined to be out-of-bounds if any of the following
+ * inequalities is true:
+ * <ul>
+ * <li>{@code fromIndex < 0}</li>
+ * <li>{@code size < 0}</li>
+ * <li>{@code fromIndex + size > length}, taking into account integer overflow</li>
+ * <li>{@code length < 0}, which is implied from the former inequalities</li>
+ * </ul>
+ *
+ * <p>If the sub-range is out-of-bounds, then a runtime exception is
+ * thrown that is the result of applying the following arguments to the
+ * exception formatter: the name of this method, {@code checkFromIndexSize};
+ * and an unmodifiable list integers whose values are, in order, the
+ * out-of-bounds arguments {@code fromIndex}, {@code size}, and
+ * {@code length}.
+ *
+ * @param <X> the type of runtime exception to throw if the arguments are
+ * out-of-bounds
+ * @param fromIndex the lower-bound (inclusive) of the sub-interval
+ * @param size the size of the sub-range
+ * @param length the upper-bound (exclusive) of the range
+ * @param oobef the exception formatter that when applied with this
+ * method name and out-of-bounds arguments returns a runtime
+ * exception. If {@code null} or returns {@code null} then, it is as
+ * if an exception formatter produced from an invocation of
+ * {@code outOfBoundsExceptionFormatter(IndexOutOfBounds::new)} is used
+ * instead (though it may be more efficient).
+ * Exceptions thrown by the formatter are relayed to the caller.
+ * @return {@code fromIndex} if the sub-range within bounds of the range
+ * @throws X if the sub-range is out-of-bounds and the exception factory
+ * function is non-{@code null}
+ * @throws IndexOutOfBoundsException if the sub-range is out-of-bounds and
+ * the exception factory function is {@code null}
+ * @since 9
+ */
+ public static <X extends RuntimeException>
+ int checkFromIndexSize(int fromIndex, int size, int length,
+ BiFunction<String, List<Integer>, X> oobef) {
+ if ((length | fromIndex | size) < 0 || size > length - fromIndex)
+ throw outOfBoundsCheckFromIndexSize(oobef, fromIndex, size, length);
+ return fromIndex;
+ }
+}
--- a/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties Sat May 14 09:11:07 2016 -0700
@@ -100,7 +100,6 @@
\ -Xdiag show additional diagnostic messages\n\
\ -Xdiag:resolver show resolver diagnostic messages\n\
\ -Xnoclassgc disable class garbage collection\n\
-\ -Xincgc enable incremental garbage collection\n\
\ -Xloggc:<file> log GC status to a file with time stamps\n\
\ -Xbatch disable background compilation\n\
\ -Xms<size> set initial Java heap size\n\
--- a/jdk/src/java.base/share/native/include/jvmti.h Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.base/share/native/include/jvmti.h Sat May 14 09:11:07 2016 -0700
@@ -704,7 +704,8 @@
unsigned int can_generate_resource_exhaustion_heap_events : 1;
unsigned int can_generate_resource_exhaustion_threads_events : 1;
unsigned int can_generate_early_vmstart : 1;
- unsigned int : 6;
+ unsigned int can_generate_early_class_hook_events : 1;
+ unsigned int : 5;
unsigned int : 16;
unsigned int : 16;
unsigned int : 16;
--- a/jdk/src/java.instrument/share/native/libinstrument/InvocationAdapter.c Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/java.instrument/share/native/libinstrument/InvocationAdapter.c Sat May 14 09:11:07 2016 -0700
@@ -518,18 +518,22 @@
splitPathList(const char* str, int* pathCount, char*** paths) {
int count = 0;
char** segments = NULL;
+ char** new_segments;
char* c = (char*) str;
while (*c != '\0') {
while (*c == ' ') c++; /* skip leading spaces */
if (*c == '\0') {
break;
}
- if (segments == NULL) {
- segments = (char**)malloc( sizeof(char**) );
- } else {
- segments = (char**)realloc( segments, (count+1)*sizeof(char**) );
+ new_segments = (char**)realloc(segments, (count+1)*sizeof(char*));
+ if (new_segments == NULL) {
+ jplis_assert(0);
+ free(segments);
+ count = 0;
+ segments = NULL;
+ break;
}
- jplis_assert(segments != (char**)NULL);
+ segments = new_segments;
segments[count++] = c;
c = strchr(c, ' ');
if (c == NULL) {
--- a/jdk/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java Sat May 14 09:11:07 2016 -0700
@@ -258,7 +258,7 @@
/*
* Convenience method for simple commands
*/
- private InputStream executeCommand(String cmd, Object ... args) throws IOException {
+ public InputStream executeCommand(String cmd, Object ... args) throws IOException {
try {
return execute(cmd, args);
} catch (AgentLoadException x) {
--- a/jdk/src/jdk.jcmd/share/classes/jdk/internal/vm/agent/spi/ToolProvider.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +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. 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.
- */
-
-package jdk.internal.vm.agent.spi;
-
-/**
- * Service interface for jdk.hotspot.agent to provide the tools that
- * jstack, jmap, jinfo will invoke, if present.
- */
-public interface ToolProvider {
- /**
- * Returns the name of the tool provider
- */
- String getName();
-
- /**
- * Invoke the tool provider with the given arguments
- */
- void run(String... arguments);
-}
--- a/jdk/src/jdk.jcmd/share/classes/jdk/internal/vm/agent/spi/ToolProviderFinder.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +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. 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.
- */
-
-package jdk.internal.vm.agent.spi;
-
-import java.lang.reflect.Layer;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-public final class ToolProviderFinder {
- private static final Map<String, ToolProvider> providers = init();
-
- public static ToolProvider find(String name) {
- return providers.get(name);
- }
-
- private static Map<String, ToolProvider> init() {
- Map<String, ToolProvider> providers = new HashMap<>();
- ServiceLoader.load(Layer.boot(), ToolProvider.class)
- .forEach(p -> providers.putIfAbsent(p.getName(), p));
- return providers;
- }
-}
--- a/jdk/src/jdk.jcmd/share/classes/module-info.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/module-info.java Sat May 14 09:11:07 2016 -0700
@@ -26,9 +26,4 @@
module jdk.jcmd {
requires jdk.attach;
requires jdk.jvmstat;
-
- exports jdk.internal.vm.agent.spi to jdk.hotspot.agent;
-
- uses jdk.internal.vm.agent.spi.ToolProvider;
}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,128 @@
+/*
+ * 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. 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.
+ */
+
+package sun.tools.common;
+
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import com.sun.tools.attach.VirtualMachine;
+import com.sun.tools.attach.VirtualMachineDescriptor;
+
+import sun.jvmstat.monitor.MonitorException;
+import sun.jvmstat.monitor.MonitoredHost;
+import sun.jvmstat.monitor.MonitoredVm;
+import sun.jvmstat.monitor.MonitoredVmUtil;
+import sun.jvmstat.monitor.VmIdentifier;
+
+/**
+ * Class for finding process matching a process argument,
+ * excluding tool it self and returning a list containing
+ * the process identifiers.
+ */
+public class ProcessArgumentMatcher {
+ private String excludeCls;
+ private String matchClass = null;
+ private String singlePid = null;
+ private boolean matchAll = false;
+
+ public ProcessArgumentMatcher(String pidArg, Class<?> excludeClass) {
+ excludeCls = excludeClass.getName();
+ if (pidArg == null || pidArg.isEmpty()) {
+ throw new IllegalArgumentException("Pid string is invalid");
+ }
+ if (pidArg.charAt(0) == '-') {
+ throw new IllegalArgumentException("Unrecognized " + pidArg);
+ }
+ try {
+ long pid = Long.parseLong(pidArg);
+ if (pid == 0) {
+ matchAll = true;
+ } else {
+ singlePid = String.valueOf(pid);
+ }
+ } catch (NumberFormatException nfe) {
+ matchClass = pidArg;
+ }
+ }
+
+ private boolean check(VirtualMachineDescriptor vmd) {
+ String mainClass = null;
+ try {
+ VmIdentifier vmId = new VmIdentifier(vmd.id());
+ MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
+ MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
+ mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
+ monitoredHost.detach(monitoredVm);
+ } catch (NullPointerException npe) {
+ // There is a potential race, where a running java app is being
+ // queried, unfortunately the java app has shutdown after this
+ // method is started but before getMonitoredVM is called.
+ // If this is the case, then the /tmp/hsperfdata_xxx/pid file
+ // will have disappeared and we will get a NullPointerException.
+ // Handle this gracefully....
+ return false;
+ } catch (MonitorException | URISyntaxException e) {
+ if (e.getMessage() != null) {
+ System.err.println(e.getMessage());
+ } else {
+ Throwable cause = e.getCause();
+ if ((cause != null) && (cause.getMessage() != null)) {
+ System.err.println(cause.getMessage());
+ } else {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ if (mainClass.equals(excludeCls)) {
+ return false;
+ }
+
+ if (matchAll || mainClass.indexOf(matchClass) != -1) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public Collection<String> getPids() {
+ Collection<String> pids = new ArrayList<>();
+ if (singlePid != null) {
+ pids.add(singlePid);
+ return pids;
+ }
+ List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
+ for (VirtualMachineDescriptor vmd : vmds) {
+ if (check(vmd)) {
+ pids.add(vmd.id());
+ }
+ }
+ return pids;
+ }
+}
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jcmd/Arguments.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jcmd/Arguments.java Sat May 14 09:11:07 2016 -0700
@@ -33,16 +33,14 @@
private boolean listProcesses = false;
private boolean listCounters = false;
private boolean showUsage = false;
- private int pid = -1;
private String command = null;
- private String processSubstring;
+ private String processString = null;
public boolean isListProcesses() { return listProcesses; }
public boolean isListCounters() { return listCounters; }
public boolean isShowUsage() { return showUsage; }
- public int getPid() { return pid; }
public String getCommand() { return command; }
- public String getProcessSubstring() { return processSubstring; }
+ public String getProcessString() { return processString; }
public Arguments(String[] args) {
if (args.length == 0 || args[0].equals("-l")) {
@@ -55,15 +53,7 @@
return;
}
- try {
- pid = Integer.parseInt(args[0]);
- } catch (NumberFormatException ex) {
- // use as a partial class-name instead
- if (args[0].charAt(0) != '-') {
- // unless it starts with a '-'
- processSubstring = args[0];
- }
- }
+ processString = args[0];
StringBuilder sb = new StringBuilder();
for (int i = 1; i < args.length; i++) {
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jcmd/JCmd.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jcmd/JCmd.java Sat May 14 09:11:07 2016 -0700
@@ -29,22 +29,22 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.net.URISyntaxException;
import com.sun.tools.attach.AttachOperationFailedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
-import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import sun.tools.attach.HotSpotVirtualMachine;
+import sun.tools.common.ProcessArgumentMatcher;
import sun.tools.jstat.JStatLogger;
import sun.jvmstat.monitor.Monitor;
import sun.jvmstat.monitor.MonitoredHost;
import sun.jvmstat.monitor.MonitoredVm;
-import sun.jvmstat.monitor.MonitoredVmUtil;
import sun.jvmstat.monitor.MonitorException;
import sun.jvmstat.monitor.VmIdentifier;
@@ -73,52 +73,18 @@
System.exit(0);
}
- List<String> pids = new ArrayList<String>();
- if (arg.getPid() == 0) {
- // find all VMs
- List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
- for (VirtualMachineDescriptor vmd : vmds) {
- if (!isJCmdProcess(vmd)) {
- pids.add(vmd.id());
- }
- }
- } else if (arg.getProcessSubstring() != null) {
- // use the partial class-name match
- List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
- for (VirtualMachineDescriptor vmd : vmds) {
- if (isJCmdProcess(vmd)) {
- continue;
- }
- try {
- String mainClass = getMainClass(vmd);
- if (mainClass != null
- && mainClass.indexOf(arg.getProcessSubstring()) != -1) {
- pids.add(vmd.id());
- }
- } catch (MonitorException|URISyntaxException e) {
- if (e.getMessage() != null) {
- System.err.println(e.getMessage());
- } else {
- Throwable cause = e.getCause();
- if ((cause != null) && (cause.getMessage() != null)) {
- System.err.println(cause.getMessage());
- } else {
- e.printStackTrace();
- }
- }
- }
- }
- if (pids.isEmpty()) {
- System.err.println("Could not find any processes matching : '"
- + arg.getProcessSubstring() + "'");
- System.exit(1);
- }
- } else if (arg.getPid() == -1) {
+ Collection<String> pids = Collections.emptyList();
+ try {
+ ProcessArgumentMatcher ap = new ProcessArgumentMatcher(arg.getProcessString(), JCmd.class);
+ pids = ap.getPids();
+ } catch (IllegalArgumentException iae) {
System.err.println("Invalid pid specified");
System.exit(1);
- } else {
- // Use the found pid
- pids.add(arg.getPid() + "");
+ }
+ if (pids.isEmpty()) {
+ System.err.println("Could not find any processes matching : '"
+ + arg.getProcessString() + "'");
+ System.exit(1);
}
boolean success = true;
@@ -199,36 +165,6 @@
}
}
- private static boolean isJCmdProcess(VirtualMachineDescriptor vmd) {
- try {
- String mainClass = getMainClass(vmd);
- return mainClass != null && mainClass.equals(JCmd.class.getName());
- } catch (URISyntaxException|MonitorException ex) {
- return false;
- }
- }
-
- private static String getMainClass(VirtualMachineDescriptor vmd)
- throws URISyntaxException, MonitorException {
- try {
- String mainClass = null;
- VmIdentifier vmId = new VmIdentifier(vmd.id());
- MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
- MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
- mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
- monitoredHost.detach(monitoredVm);
- return mainClass;
- } catch(NullPointerException e) {
- // There is a potential race, where a running java app is being
- // queried, unfortunately the java app has shutdown after this
- // method is started but before getMonitoredVM is called.
- // If this is the case, then the /tmp/hsperfdata_xxx/pid file
- // will have disappeared and we will get a NullPointerException.
- // Handle this gracefully....
- return null;
- }
- }
-
/**
* Class to compare two Monitor objects by name in ascending order.
* (from jstat)
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java Sat May 14 09:11:07 2016 -0700
@@ -25,15 +25,14 @@
package sun.tools.jinfo;
-import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
import com.sun.tools.attach.VirtualMachine;
import sun.tools.attach.HotSpotVirtualMachine;
-import jdk.internal.vm.agent.spi.ToolProvider;
-import jdk.internal.vm.agent.spi.ToolProviderFinder;
+import sun.tools.common.ProcessArgumentMatcher;
/*
* This class is the main class for the JInfo utility. It parses its arguments
@@ -41,157 +40,96 @@
* or an SA tool.
*/
final public class JInfo {
- private static final String SA_JINFO_TOOL_NAME = "jinfo";
- private boolean useSA = false;
- private String[] args = null;
- private JInfo(String[] args) throws IllegalArgumentException {
+ public static void main(String[] args) throws Exception {
if (args.length == 0) {
- throw new IllegalArgumentException();
+ usage(1); // no arguments
}
+ checkForUnsupportedOptions(args);
- int argCopyIndex = 0;
- // First determine if we should launch SA or not
- if (args[0].equals("-F")) {
- // delete the -F
- argCopyIndex = 1;
- useSA = true;
- } else if (args[0].equals("-flags")
- || args[0].equals("-sysprops"))
- {
- if (args.length == 2) {
- if (!isPid(args[1])) {
- // If args[1] doesn't parse to a number then
- // it must be the SA debug server
- // (otherwise it is the pid)
- useSA = true;
- }
- } else if (args.length == 3) {
- // arguments include an executable and a core file
- useSA = true;
- } else {
- throw new IllegalArgumentException();
+ boolean doFlag = false;
+ boolean doFlags = false;
+ boolean doSysprops = false;
+
+ // Parse the options (arguments starting with "-" )
+ int optionCount = 0;
+ while (optionCount < args.length) {
+ String arg = args[optionCount];
+ if (!arg.startsWith("-")) {
+ break;
}
- } else if (!args[0].startsWith("-")) {
- if (args.length == 2) {
- // the only arguments are an executable and a core file
- useSA = true;
- } else if (args.length == 1) {
- if (!isPid(args[0])) {
- // The only argument is not a PID; it must be SA debug
- // server
- useSA = true;
- }
- } else {
- throw new IllegalArgumentException();
+
+ optionCount++;
+
+ if (arg.equals("-help") || arg.equals("-h")) {
+ usage(0);
}
- } else if (args[0].equals("-h") || args[0].equals("-help")) {
- if (args.length > 1) {
- throw new IllegalArgumentException();
+
+ if (arg.equals("-flag")) {
+ doFlag = true;
+ continue;
}
- } else if (args[0].equals("-flag")) {
- if (args.length == 3) {
- if (!isPid(args[2])) {
- throw new IllegalArgumentException();
- }
- } else {
- throw new IllegalArgumentException();
+
+ if (arg.equals("-flags")) {
+ doFlags = true;
+ continue;
}
- } else {
- throw new IllegalArgumentException();
- }
- this.args = Arrays.copyOfRange(args, argCopyIndex, args.length);
- }
-
- @SuppressWarnings("fallthrough")
- private void execute() throws Exception {
- if (args[0].equals("-h")
- || args[0].equals("-help")) {
- usage(0);
+ if (arg.equals("-sysprops")) {
+ doSysprops = true;
+ continue;
+ }
}
- if (useSA) {
- // SA only supports -flags or -sysprops
- if (args[0].startsWith("-")) {
- if (!(args[0].equals("-flags") || args[0].equals("-sysprops"))) {
- usage(1);
+ // Next we check the parameter count. -flag allows extra parameters
+ int paramCount = args.length - optionCount;
+ if ((doFlag && paramCount != 2) || ((!doFlag && paramCount != 1))) {
+ usage(1);
+ }
+
+ if (!doFlag && !doFlags && !doSysprops) {
+ // Print flags and sysporps if no options given
+ ProcessArgumentMatcher ap = new ProcessArgumentMatcher(args[optionCount], JInfo.class);
+ Collection<String> pids = ap.getPids();
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
+ }
+ sysprops(pid);
+ System.out.println();
+ flags(pid);
+ System.out.println();
+ commandLine(pid);
+ }
+ }
+
+ if (doFlag) {
+ ProcessArgumentMatcher ap = new ProcessArgumentMatcher(args[optionCount+1], JInfo.class);
+ Collection<String> pids = ap.getPids();
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
+ }
+ flag(pid, args[optionCount]);
+ }
+ }
+ else if (doFlags || doSysprops) {
+ ProcessArgumentMatcher ap = new ProcessArgumentMatcher(args[optionCount], JInfo.class);
+ Collection<String> pids = ap.getPids();
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
+ }
+ if (doFlags) {
+ flags(pid);
+ }
+ else if (doSysprops) {
+ sysprops(pid);
}
}
-
- // invoke SA which does it's own argument parsing
- runTool();
-
- } else {
- // Now we can parse arguments for the non-SA case
- String pid = null;
-
- switch(args[0]) {
- case "-flag":
- if (args.length != 3) {
- usage(1);
- }
- String option = args[1];
- pid = args[2];
- flag(pid, option);
- break;
- case "-flags":
- if (args.length != 2) {
- usage(1);
- }
- pid = args[1];
- flags(pid);
- break;
- case "-sysprops":
- if (args.length != 2) {
- usage(1);
- }
- pid = args[1];
- sysprops(pid);
- break;
- case "-help":
- case "-h":
- usage(0);
- // Fall through
- default:
- if (args.length == 1) {
- // no flags specified, we do -sysprops and -flags
- pid = args[0];
- sysprops(pid);
- System.out.println();
- flags(pid);
- System.out.println();
- commandLine(pid);
- } else {
- usage(1);
- }
- }
}
}
- public static void main(String[] args) throws Exception {
- JInfo jinfo = null;
- try {
- jinfo = new JInfo(args);
- jinfo.execute();
- } catch (IllegalArgumentException e) {
- usage(1);
- }
- }
-
- private static boolean isPid(String arg) {
- return arg.matches("[0-9]+");
- }
-
- // Invoke SA tool with the given arguments
- private void runTool() throws Exception {
- ToolProvider tool = ToolProviderFinder.find(SA_JINFO_TOOL_NAME);
- if (tool == null) {
- usage(1);
- }
- tool.run(args);
- }
-
private static void flag(String pid, String option) throws IOException {
HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
String flag;
@@ -274,46 +212,49 @@
vm.detach();
}
-
- // print usage message
- private static void usage(int exit) {
- boolean usageSA = ToolProviderFinder.find(SA_JINFO_TOOL_NAME) != null;
+ private static void checkForUnsupportedOptions(String[] args) {
+ // Check arguments for -F, and non-numeric value
+ // and warn the user that SA is not supported anymore
+ int maxCount = 1;
+ int paramCount = 0;
- System.err.println("Usage:");
- if (usageSA) {
- System.err.println(" jinfo [option] <pid>");
- System.err.println(" (to connect to a running process)");
- System.err.println(" jinfo -F [option] <pid>");
- System.err.println(" (to connect to a hung process)");
- System.err.println(" jinfo [option] <executable> <core>");
- System.err.println(" (to connect to a core file)");
- System.err.println(" jinfo [option] [server_id@]<remote server IP or hostname>");
- System.err.println(" (to connect to remote debug server)");
- System.err.println("");
- System.err.println("where <option> is one of:");
- System.err.println(" for running processes:");
- System.err.println(" -flag <name> to print the value of the named VM flag");
- System.err.println(" -flag [+|-]<name> to enable or disable the named VM flag");
- System.err.println(" -flag <name>=<value> to set the named VM flag to the given value");
- System.err.println(" for running or hung processes and core files:");
- System.err.println(" -flags to print VM flags");
- System.err.println(" -sysprops to print Java system properties");
- System.err.println(" <no option> to print both VM flags and system properties");
- System.err.println(" -h | -help to print this help message");
- } else {
- System.err.println(" jinfo <option> <pid>");
- System.err.println(" (to connect to a running process)");
- System.err.println("");
- System.err.println("where <option> is one of:");
- System.err.println(" -flag <name> to print the value of the named VM flag");
- System.err.println(" -flag [+|-]<name> to enable or disable the named VM flag");
- System.err.println(" -flag <name>=<value> to set the named VM flag to the given value");
- System.err.println(" -flags to print VM flags");
- System.err.println(" -sysprops to print Java system properties");
- System.err.println(" <no option> to print both VM flags and system properties");
- System.err.println(" -h | -help to print this help message");
+ for (String s : args) {
+ if (s.equals("-F")) {
+ SAOptionError("-F option used");
+ }
+ if (s.equals("-flag")) {
+ maxCount = 2;
+ }
+ if (! s.startsWith("-")) {
+ paramCount += 1;
+ }
}
+ if (paramCount > maxCount) {
+ SAOptionError("More than " + maxCount + " non-option argument");
+ }
+ }
+
+ private static void SAOptionError(String msg) {
+ System.err.println("Error: " + msg);
+ System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jinfo instead");
+ System.exit(1);
+ }
+
+ // print usage message
+ private static void usage(int exit) {
+ System.err.println("Usage:");
+ System.err.println(" jinfo <option> <pid>");
+ System.err.println(" (to connect to a running process)");
+ System.err.println("");
+ System.err.println("where <option> is one of:");
+ System.err.println(" -flag <name> to print the value of the named VM flag");
+ System.err.println(" -flag [+|-]<name> to enable or disable the named VM flag");
+ System.err.println(" -flag <name>=<value> to set the named VM flag to the given value");
+ System.err.println(" -flags to print VM flags");
+ System.err.println(" -sysprops to print Java system properties");
+ System.err.println(" <no option> to print both VM flags and system properties");
+ System.err.println(" -h | -help to print this help message");
System.exit(exit);
}
}
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java Sat May 14 09:11:07 2016 -0700
@@ -28,12 +28,13 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.AttachNotSupportedException;
import sun.tools.attach.HotSpotVirtualMachine;
-import jdk.internal.vm.agent.spi.ToolProvider;
-import jdk.internal.vm.agent.spi.ToolProviderFinder;
+import sun.tools.common.ProcessArgumentMatcher;
/*
* This class is the main class for the JMap utility. It parses its arguments
@@ -44,34 +45,18 @@
*/
public class JMap {
- // Options handled by the attach mechanism
- private static String HISTO_OPTION = "-histo";
- private static String LIVE_HISTO_OPTION = "-histo:live";
- private static String DUMP_OPTION_PREFIX = "-dump:";
-
- // These options imply the use of a SA tool
- private static String SA_TOOL_OPTIONS =
- "-heap|-heap:format=b|-clstats|-finalizerinfo";
-
- // The -F (force) option is currently not passed through to SA
- private static String FORCE_SA_OPTION = "-F";
-
- // Default option (if nothing provided)
- private static String DEFAULT_OPTION = "-pmap";
-
public static void main(String[] args) throws Exception {
if (args.length == 0) {
usage(1); // no arguments
}
- // used to indicate if we should use SA
- boolean useSA = false;
+ checkForUnsupportedOptions(args);
- // the chosen option (-heap, -dump:*, ... )
+ // the chosen option
String option = null;
// First iterate over the options (arguments starting with -). There should be
- // one (but maybe two if -F is also used).
+ // one.
int optionCount = 0;
while (optionCount < args.length) {
String arg = args[optionCount];
@@ -80,8 +65,6 @@
}
if (arg.equals("-help") || arg.equals("-h")) {
usage(0);
- } else if (arg.equals(FORCE_SA_OPTION)) {
- useSA = true;
} else {
if (option != null) {
usage(1); // option already specified
@@ -93,123 +76,102 @@
// if no option provided then use default.
if (option == null) {
- option = DEFAULT_OPTION;
- }
- if (option.matches(SA_TOOL_OPTIONS)) {
- useSA = true;
+ usage(0);
}
- // Next we check the parameter count. For the SA tools there are
- // one or two parameters. For the built-in -dump option there is
- // only one parameter (the process-id)
+ // Next we check the parameter count.
int paramCount = args.length - optionCount;
- if (paramCount == 0 || paramCount > 2) {
+ if (paramCount != 1) {
usage(1);
}
- if (optionCount == 0 || paramCount != 1) {
- useSA = true;
- } else {
- // the parameter for the -dump option is a process-id.
- // If it doesn't parse to a number then it must be SA
- // debug server
- if (!args[optionCount].matches("[0-9]+")) {
- useSA = true;
+ String pidArg = args[1];
+ // Here we handle the built-in options
+ // As more options are added we should create an abstract tool class and
+ // have a table to map the options
+ ProcessArgumentMatcher ap = new ProcessArgumentMatcher(pidArg, JMap.class);
+ Collection<String> pids = ap.getPids();
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
}
- }
-
-
- // at this point we know if we are executing an SA tool or a built-in
- // option.
-
- if (useSA) {
- // parameters (<pid> or <exe> <core>)
- String params[] = new String[paramCount];
- for (int i=optionCount; i<args.length; i++ ){
- params[i-optionCount] = args[i];
- }
- runTool(option, params);
-
- } else {
- String pid = args[1];
- // Here we handle the built-in options
- // As more options are added we should create an abstract tool class and
- // have a table to map the options
- if (option.equals(HISTO_OPTION)) {
- histo(pid, false);
- } else if (option.equals(LIVE_HISTO_OPTION)) {
- histo(pid, true);
- } else if (option.startsWith(DUMP_OPTION_PREFIX)) {
- dump(pid, option);
+ if (option.equals("-histo")) {
+ histo(pid, "");
+ } else if (option.startsWith("-histo:")) {
+ histo(pid, option.substring("-histo:".length()));
+ } else if (option.startsWith("-dump:")) {
+ dump(pid, option.substring("-dump:".length()));
+ } else if (option.equals("-finalizerinfo")) {
+ executeCommandForPid(pid, "jcmd", "GC.finalizer_info");
+ } else if (option.equals("-clstats")) {
+ executeCommandForPid(pid, "jcmd", "GC.class_stats");
} else {
- usage(1);
+ usage(1);
}
}
}
- // Invoke SA tool with the given arguments
- private static void runTool(String option, String args[]) throws Exception {
- String[][] tools = {
- { "-pmap", "pmap" },
- { "-heap", "heapSummary" },
- { "-heap:format=b", "heapDumper" },
- { "-histo", "objectHistogram" },
- { "-clstats", "classLoaderStats" },
- { "-finalizerinfo", "finalizerInfo" },
- };
-
- String name = null;
-
- // -dump option needs to be handled in a special way
- if (option.startsWith(DUMP_OPTION_PREFIX)) {
- // first check that the option can be parsed
- String fn = parseDumpOptions(option);
- if (fn == null) {
- usage(1);
- }
+ private static void executeCommandForPid(String pid, String command, Object ... args)
+ throws AttachNotSupportedException, IOException,
+ UnsupportedEncodingException {
+ VirtualMachine vm = VirtualMachine.attach(pid);
- // tool for heap dumping
- name = "heapDumper";
+ // Cast to HotSpotVirtualMachine as this is an
+ // implementation specific method.
+ HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
+ try (InputStream in = hvm.executeCommand(command, args)) {
+ // read to EOF and just print output
+ byte b[] = new byte[256];
+ int n;
+ do {
+ n = in.read(b);
+ if (n > 0) {
+ String s = new String(b, 0, n, "UTF-8");
+ System.out.print(s);
+ }
+ } while (n > 0);
+ }
+ vm.detach();
+ }
- // HeapDumper -f <file>
- args = prepend(fn, args);
- args = prepend("-f", args);
- } else {
- int i=0;
- while (i < tools.length) {
- if (option.equals(tools[i][0])) {
- name = tools[i][1];
- break;
- }
- i++;
- }
+ private static void histo(String pid, String options)
+ throws AttachNotSupportedException, IOException,
+ UnsupportedEncodingException {
+ String liveopt = "-all";
+ if (options.equals("") || options.equals("all")) {
+ // pass
}
- if (name == null) {
- usage(1); // no mapping to tool
+ else if (options.equals("live")) {
+ liveopt = "-live";
}
-
- // Tool not available on this platform.
- ToolProvider tool = ToolProviderFinder.find(name);
- if (tool == null) {
+ else {
usage(1);
}
- // invoke the main method with the arguments
- tool.run(args);
+ // inspectHeap is not the same as jcmd GC.class_histogram
+ executeCommandForPid(pid, "inspectheap", liveopt);
}
- private static final String LIVE_OBJECTS_OPTION = "-live";
- private static final String ALL_OBJECTS_OPTION = "-all";
- private static void histo(String pid, boolean live) throws IOException {
- VirtualMachine vm = attach(pid);
- InputStream in = ((HotSpotVirtualMachine)vm).
- heapHisto(live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION);
- drain(vm, in);
- }
+ private static void dump(String pid, String options)
+ throws AttachNotSupportedException, IOException,
+ UnsupportedEncodingException {
+
+ String subopts[] = options.split(",");
+ String filename = null;
+ String liveopt = "-all";
- private static void dump(String pid, String options) throws IOException {
- // parse the options to get the dump filename
- String filename = parseDumpOptions(options);
+ for (int i = 0; i < subopts.length; i++) {
+ String subopt = subopts[i];
+ if (subopt.equals("live")) {
+ liveopt = "-live";
+ } else if (subopt.startsWith("file=")) {
+ // file=<file> - check that <file> is specified
+ if (subopt.length() > 5) {
+ filename = subopt.substring(5);
+ }
+ }
+ }
+
if (filename == null) {
usage(1); // invalid options or no filename
}
@@ -219,156 +181,73 @@
// working directory rather than the directory where jmap
// is executed.
filename = new File(filename).getCanonicalPath();
-
- // dump live objects only or not
- boolean live = isDumpLiveObjects(options);
-
- VirtualMachine vm = attach(pid);
- System.out.println("Dumping heap to " + filename + " ...");
- InputStream in = ((HotSpotVirtualMachine)vm).
- dumpHeap((Object)filename,
- (live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION));
- drain(vm, in);
+ // dumpHeap is not the same as jcmd GC.heap_dump
+ executeCommandForPid(pid, "dumpheap", filename, liveopt);
}
- // Parse the options to the -dump option. Valid options are format=b and
- // file=<file>. Returns <file> if provided. Returns null if <file> not
- // provided, or invalid option.
- private static String parseDumpOptions(String arg) {
- assert arg.startsWith(DUMP_OPTION_PREFIX);
+ private static void checkForUnsupportedOptions(String[] args) {
+ // Check arguments for -F, -m, and non-numeric value
+ // and warn the user that SA is not supported anymore
+
+ int paramCount = 0;
- String filename = null;
+ for (String s : args) {
+ if (s.equals("-F")) {
+ SAOptionError("-F option used");
+ }
- // options are separated by comma (,)
- String options[] = arg.substring(DUMP_OPTION_PREFIX.length()).split(",");
-
- for (int i=0; i<options.length; i++) {
- String option = options[i];
+ if (s.equals("-heap")) {
+ SAOptionError("-heap option used");
+ }
- if (option.equals("format=b")) {
- // ignore format (not needed at this time)
- } else if (option.equals("live")) {
- // a valid suboption
- } else {
+ /* Reimplemented using jcmd, output format is different
+ from original one
+
+ if (s.equals("-clstats")) {
+ warnSA("-clstats option used");
+ }
- // file=<file> - check that <file> is specified
- if (option.startsWith("file=")) {
- filename = option.substring(5);
- if (filename.length() == 0) {
- return null;
- }
- } else {
- return null; // option not recognized
- }
+ if (s.equals("-finalizerinfo")) {
+ warnSA("-finalizerinfo option used");
+ }
+ */
+
+ if (! s.startsWith("-")) {
+ paramCount += 1;
}
}
- return filename;
- }
- private static boolean isDumpLiveObjects(String arg) {
- // options are separated by comma (,)
- String options[] = arg.substring(DUMP_OPTION_PREFIX.length()).split(",");
- for (String suboption : options) {
- if (suboption.equals("live")) {
- return true;
- }
- }
- return false;
- }
-
- // Attach to <pid>, existing if we fail to attach
- private static VirtualMachine attach(String pid) {
- try {
- return VirtualMachine.attach(pid);
- } catch (Exception x) {
- String msg = x.getMessage();
- if (msg != null) {
- System.err.println(pid + ": " + msg);
- } else {
- x.printStackTrace();
- }
- if ((x instanceof AttachNotSupportedException) && haveSA()) {
- System.err.println("The -F option can be used when the " +
- "target process is not responding");
- }
- System.exit(1);
- return null; // keep compiler happy
+ if (paramCount > 1) {
+ SAOptionError("More than one non-option argument");
}
}
- // Read the stream from the target VM until EOF, then detach
- private static void drain(VirtualMachine vm, InputStream in) throws IOException {
- // read to EOF and just print output
- byte b[] = new byte[256];
- int n;
- do {
- n = in.read(b);
- if (n > 0) {
- String s = new String(b, 0, n, "UTF-8");
- System.out.print(s);
- }
- } while (n > 0);
- in.close();
- vm.detach();
- }
-
- // return a new string array with arg as the first element
- private static String[] prepend(String arg, String args[]) {
- String[] newargs = new String[args.length+1];
- newargs[0] = arg;
- System.arraycopy(args, 0, newargs, 1, args.length);
- return newargs;
- }
-
- // returns true if SA is available
- private static boolean haveSA() {
- return ToolProviderFinder.find("heapSummary") != null;
+ private static void SAOptionError(String msg) {
+ System.err.println("Error: " + msg);
+ System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jmap instead");
+ System.exit(1);
}
// print usage message
private static void usage(int exit) {
System.err.println("Usage:");
- if (haveSA()) {
- System.err.println(" jmap [option] <pid>");
- System.err.println(" (to connect to running process)");
- System.err.println(" jmap [option] <executable <core>");
- System.err.println(" (to connect to a core file)");
- System.err.println(" jmap [option] [server_id@]<remote server IP or hostname>");
- System.err.println(" (to connect to remote debug server)");
- System.err.println("");
- System.err.println("where <option> is one of:");
- System.err.println(" <none> to print same info as Solaris pmap");
- System.err.println(" -heap to print java heap summary");
- System.err.println(" -histo[:live] to print histogram of java object heap; if the \"live\"");
- System.err.println(" suboption is specified, only count live objects");
- System.err.println(" -clstats to print class loader statistics");
- System.err.println(" -finalizerinfo to print information on objects awaiting finalization");
- System.err.println(" -dump:<dump-options> to dump java heap in hprof binary format");
- System.err.println(" dump-options:");
- System.err.println(" live dump only live objects; if not specified,");
- System.err.println(" all objects in the heap are dumped.");
- System.err.println(" format=b binary format");
- System.err.println(" file=<file> dump heap to <file>");
- System.err.println(" Example: jmap -dump:live,format=b,file=heap.bin <pid>");
- System.err.println(" -F force. Use with -dump:<dump-options> <pid> or -histo");
- System.err.println(" to force a heap dump or histogram when <pid> does not");
- System.err.println(" respond. The \"live\" suboption is not supported");
- System.err.println(" in this mode.");
- System.err.println(" -h | -help to print this help message");
- System.err.println(" -J<flag> to pass <flag> directly to the runtime system");
- } else {
- System.err.println(" jmap -histo <pid>");
- System.err.println(" (to connect to running process and print histogram of java object heap");
- System.err.println(" jmap -dump:<dump-options> <pid>");
- System.err.println(" (to connect to running process and dump java heap)");
- System.err.println("");
- System.err.println(" dump-options:");
- System.err.println(" format=b binary default");
- System.err.println(" file=<file> dump heap to <file>");
- System.err.println("");
- System.err.println(" Example: jmap -dump:format=b,file=heap.bin <pid>");
- }
-
+ System.err.println(" jmap -clstats <pid>");
+ System.err.println(" to connect to running process and print class loader statistics");
+ System.err.println(" jmap -finalizerinfo <pid>");
+ System.err.println(" to connect to running process and print information on objects awaiting finalization");
+ System.err.println(" jmap -histo[:live] <pid>");
+ System.err.println(" to connect to running process and print histogram of java object heap");
+ System.err.println(" if the \"live\" suboption is specified, only count live objects");
+ System.err.println(" jmap -dump:<dump-options> <pid>");
+ System.err.println(" to connect to running process and dump java heap");
+ System.err.println("");
+ System.err.println(" dump-options:");
+ System.err.println(" live dump only live objects; if not specified,");
+ System.err.println(" all objects in the heap are dumped.");
+ System.err.println(" format=b binary format");
+ System.err.println(" file=<file> dump heap to <file>");
+ System.err.println("");
+ System.err.println(" Example: jmap -dump:live,format=b,file=heap.bin <pid>");
System.exit(exit);
}
}
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java Sat May 14 09:11:07 2016 -0700
@@ -26,12 +26,11 @@
package sun.tools.jstack;
import java.io.InputStream;
+import java.util.Collection;
import com.sun.tools.attach.VirtualMachine;
-import com.sun.tools.attach.AttachNotSupportedException;
import sun.tools.attach.HotSpotVirtualMachine;
-import jdk.internal.vm.agent.spi.ToolProvider;
-import jdk.internal.vm.agent.spi.ToolProviderFinder;
+import sun.tools.common.ProcessArgumentMatcher;
/*
* This class is the main class for the JStack utility. It parses its arguments
@@ -39,15 +38,14 @@
* obtained the thread dump from a target process using the VM attach mechanism
*/
public class JStack {
- private static final String SA_JSTACK_TOOL_NAME = "jstack";
public static void main(String[] args) throws Exception {
if (args.length == 0) {
usage(1); // no arguments
}
- boolean useSA = false;
- boolean mixed = false;
+ checkForUnsupportedOptions(args);
+
boolean locks = false;
// Parse the options (arguments starting with "-" )
@@ -60,87 +58,40 @@
if (arg.equals("-help") || arg.equals("-h")) {
usage(0);
}
- else if (arg.equals("-F")) {
- useSA = true;
- }
else {
- if (arg.equals("-m")) {
- mixed = true;
+ if (arg.equals("-l")) {
+ locks = true;
} else {
- if (arg.equals("-l")) {
- locks = true;
- } else {
- usage(1);
- }
+ usage(1);
}
}
optionCount++;
}
- // mixed stack implies SA tool
- if (mixed) {
- useSA = true;
- }
-
- // Next we check the parameter count. If there are two parameters
- // we assume core file and executable so we use SA.
+ // Next we check the parameter count.
int paramCount = args.length - optionCount;
- if (paramCount == 0 || paramCount > 2) {
+ if (paramCount != 1) {
usage(1);
}
- if (paramCount == 2) {
- useSA = true;
+
+ // pass -l to thread dump operation to get extra lock info
+ String pidArg = args[optionCount];
+ String params[];
+ if (locks) {
+ params = new String[] { "-l" };
} else {
- // If we can't parse it as a pid then it must be debug server
- if (!args[optionCount].matches("[0-9]+")) {
- useSA = true;
- }
+ params = new String[0];
}
-
- // now execute using the SA JStack tool or the built-in thread dumper
- if (useSA) {
- // parameters (<pid> or <exe> <core>
- String params[] = new String[paramCount];
- for (int i=optionCount; i<args.length; i++ ){
- params[i-optionCount] = args[i];
- }
- runJStackTool(mixed, locks, params);
- } else {
- // pass -l to thread dump operation to get extra lock info
- String pid = args[optionCount];
- String params[];
- if (locks) {
- params = new String[] { "-l" };
- } else {
- params = new String[0];
+ ProcessArgumentMatcher ap = new ProcessArgumentMatcher(pidArg, JStack.class);
+ Collection<String> pids = ap.getPids();
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
}
runThreadDump(pid, params);
}
}
- // SA JStack tool
- private static boolean isAgentToolPresent() {
- return ToolProviderFinder.find(SA_JSTACK_TOOL_NAME) != null;
- }
-
- private static void runJStackTool(boolean mixed, boolean locks, String args[]) throws Exception {
- ToolProvider tool = ToolProviderFinder.find(SA_JSTACK_TOOL_NAME);
- if (tool == null) {
- usage(1); // SA not available
- }
-
- // JStack tool also takes -m and -l arguments
- if (mixed) {
- args = prepend("-m", args);
- }
- if (locks) {
- args = prepend("-l", args);
- }
-
- tool.run(args);
- }
-
-
// Attach to pid and perform a thread dump
private static void runThreadDump(String pid, String args[]) throws Exception {
VirtualMachine vm = null;
@@ -153,10 +104,6 @@
} else {
x.printStackTrace();
}
- if ((x instanceof AttachNotSupportedException) && isAgentToolPresent()) {
- System.err.println("The -F option can be used when the target " +
- "process is not responding");
- }
System.exit(1);
}
@@ -178,12 +125,35 @@
vm.detach();
}
- // return a new string array with arg as the first element
- private static String[] prepend(String arg, String args[]) {
- String[] newargs = new String[args.length+1];
- newargs[0] = arg;
- System.arraycopy(args, 0, newargs, 1, args.length);
- return newargs;
+ private static void checkForUnsupportedOptions(String[] args) {
+ // Check arguments for -F, -m, and non-numeric value
+ // and warn the user that SA is not supported anymore
+
+ int paramCount = 0;
+
+ for (String s : args) {
+ if (s.equals("-F")) {
+ SAOptionError("-F option used");
+ }
+
+ if (s.equals("-m")) {
+ SAOptionError("-m option used");
+ }
+
+ if (! s.startsWith("-")) {
+ paramCount += 1;
+ }
+ }
+
+ if (paramCount > 1) {
+ SAOptionError("More than one non-option argument");
+ }
+ }
+
+ private static void SAOptionError(String msg) {
+ System.err.println("Error: " + msg);
+ System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jstack instead");
+ System.exit(1);
}
// print usage message
@@ -191,25 +161,8 @@
System.err.println("Usage:");
System.err.println(" jstack [-l] <pid>");
System.err.println(" (to connect to running process)");
-
- if (isAgentToolPresent()) {
- System.err.println(" jstack -F [-m] [-l] <pid>");
- System.err.println(" (to connect to a hung process)");
- System.err.println(" jstack [-m] [-l] <executable> <core>");
- System.err.println(" (to connect to a core file)");
- System.err.println(" jstack [-m] [-l] [server_id@]<remote server IP or hostname>");
- System.err.println(" (to connect to a remote debug server)");
- }
-
System.err.println("");
System.err.println("Options:");
-
- if (isAgentToolPresent()) {
- System.err.println(" -F to force a thread dump. Use when jstack <pid> does not respond" +
- " (process is hung)");
- System.err.println(" -m to print both java and native frames (mixed mode)");
- }
-
System.err.println(" -l long listing. Prints additional information about locks");
System.err.println(" -h or -help to print this help message");
System.exit(exit);
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Commands.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Commands.java Sat May 14 09:11:07 2016 -0700
@@ -1534,7 +1534,6 @@
PathSearchingVirtualMachine vm = (PathSearchingVirtualMachine)Env.vm();
MessageOutput.println("base directory:", vm.baseDirectory());
MessageOutput.println("classpath:", vm.classPath().toString());
- MessageOutput.println("bootclasspath:", vm.bootClassPath().toString());
} else {
MessageOutput.println("The VM does not use paths");
}
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/EventHandler.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/EventHandler.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -133,6 +133,10 @@
if (!vmDied) {
vmDisconnectEvent(event);
}
+ /*
+ * Inform jdb command line processor that jdb is being shutdown. JDK-8154144.
+ */
+ ((TTY)notifier).setShuttingDown(true);
Env.shutdown(shutdownMessageKey);
return false;
} else {
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -56,6 +56,16 @@
*/
private static final String progname = "jdb";
+ private volatile boolean shuttingDown = false;
+
+ public void setShuttingDown(boolean s) {
+ shuttingDown = s;
+ }
+
+ public boolean isShuttingDown() {
+ return shuttingDown;
+ }
+
@Override
public void vmStartEvent(VMStartEvent se) {
Thread.yield(); // fetch output
@@ -750,7 +760,13 @@
while (true) {
String ln = in.readLine();
if (ln == null) {
- MessageOutput.println("Input stream closed.");
+ /*
+ * Jdb is being shutdown because debuggee exited, ignore any 'null'
+ * returned by readLine() during shutdown. JDK-8154144.
+ */
+ if (!isShuttingDown()) {
+ MessageOutput.println("Input stream closed.");
+ }
ln = "quit";
}
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources.java Sat May 14 09:11:07 2016 -0700
@@ -74,7 +74,6 @@
{"Array element is not a method", "Array element is not a method"},
{"Array index must be a integer type", "Array index must be a integer type"},
{"base directory:", "base directory: {0}"},
- {"bootclasspath:", "bootclasspath: {0}"},
{"Breakpoint hit:", "Breakpoint hit: "},
{"breakpoint", "breakpoint {0}"},
{"Breakpoints set:", "Breakpoints set:"},
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources_ja.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources_ja.java Sat May 14 09:11:07 2016 -0700
@@ -74,7 +74,6 @@
{"Array element is not a method", "\u914D\u5217\u8981\u7D20\u306F\u30E1\u30BD\u30C3\u30C9\u3067\u306F\u3042\u308A\u307E\u305B\u3093"},
{"Array index must be a integer type", "\u914D\u5217\u306E\u6DFB\u3048\u5B57\u306F\u6574\u6570\u578B\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059"},
{"base directory:", "\u30D9\u30FC\u30B9\u30FB\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA: {0}"},
- {"bootclasspath:", "\u30D6\u30FC\u30C8\u30FB\u30AF\u30E9\u30B9\u30D1\u30B9: {0}"},
{"Breakpoint hit:", "\u30D2\u30C3\u30C8\u3057\u305F\u30D6\u30EC\u30FC\u30AF\u30DD\u30A4\u30F3\u30C8: "},
{"breakpoint", "\u30D6\u30EC\u30FC\u30AF\u30DD\u30A4\u30F3\u30C8{0}"},
{"Breakpoints set:", "\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u30D6\u30EC\u30FC\u30AF\u30DD\u30A4\u30F3\u30C8:"},
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources_zh_CN.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources_zh_CN.java Sat May 14 09:11:07 2016 -0700
@@ -74,7 +74,6 @@
{"Array element is not a method", "\u6570\u7EC4\u5143\u7D20\u4E0D\u662F\u65B9\u6CD5"},
{"Array index must be a integer type", "\u6570\u7EC4\u7D22\u5F15\u5FC5\u987B\u4E3A\u6574\u6570\u7C7B\u578B"},
{"base directory:", "\u57FA\u76EE\u5F55: {0}"},
- {"bootclasspath:", "\u5F15\u5BFC\u7C7B\u8DEF\u5F84: {0}"},
{"Breakpoint hit:", "\u65AD\u70B9\u547D\u4E2D: "},
{"breakpoint", "\u65AD\u70B9{0}"},
{"Breakpoints set:", "\u65AD\u70B9\u96C6:"},
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java Sat May 14 09:11:07 2016 -0700
@@ -1439,7 +1439,7 @@
}
public List<String> bootClassPath() {
- return Arrays.asList(getClasspath().bootclasspaths);
+ return Collections.emptyList();
}
public String baseDirectory() {
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c Sat May 14 09:11:07 2016 -0700
@@ -126,7 +126,7 @@
int writtenCount = 0;
int i;
- for (i=0; i<classCount; i++) {
+ for (i = 0; i < classCount; i++) {
jclass clazz = theClasses[i];
jint status = classStatus(clazz);
char *candidate_signature = NULL;
@@ -141,7 +141,13 @@
error = classSignature(clazz, &candidate_signature, NULL);
if (error != JVMTI_ERROR_NONE) {
- break;
+ // Clazz become invalid since the time we get the class list
+ // Skip this entry
+ if (error == JVMTI_ERROR_INVALID_CLASS) {
+ continue;
+ }
+
+ break;
}
if (strcmp(candidate_signature, signature) == 0) {
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c Sat May 14 09:11:07 2016 -0700
@@ -277,12 +277,14 @@
JDI_ASSERT(thread);
+ debugMonitorEnter(invokerLock);
request = threadControl_getInvokeRequest(thread);
if (request == NULL) {
EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
}
request->available = JNI_TRUE;
+ debugMonitorExit(invokerLock);
}
jvmtiError
@@ -739,29 +741,20 @@
}
jboolean
-invoker_isPending(jthread thread)
+invoker_isEnabled(jthread thread)
{
InvokeRequest *request;
+ jboolean isEnabled;
JDI_ASSERT(thread);
+ debugMonitorEnter(invokerLock);
request = threadControl_getInvokeRequest(thread);
if (request == NULL) {
EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
}
- return request->pending;
-}
-
-jboolean
-invoker_isEnabled(jthread thread)
-{
- InvokeRequest *request;
-
- JDI_ASSERT(thread);
- request = threadControl_getInvokeRequest(thread);
- if (request == NULL) {
- EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting thread invoke request");
- }
- return request->available;
+ isEnabled = request->available;
+ debugMonitorExit(invokerLock);
+ return isEnabled;
}
void
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/invoker.h Sat May 14 03:45:59 2016 +0000
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/invoker.h Sat May 14 09:11:07 2016 -0700
@@ -67,7 +67,6 @@
jboolean invoker_doInvoke(jthread thread);
void invoker_completeInvokeRequest(jthread thread);
-jboolean invoker_isPending(jthread thread);
jboolean invoker_isEnabled(jthread thread);
void invoker_detach(InvokeRequest *request);
--- a/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh Sat May 14 09:11:07 2016 -0700
@@ -106,7 +106,7 @@
# run test
${TESTJAVA}${FS}bin${FS}java \
${TESTVMOPTS} \
- -verbose:class -Xlog:classload -cp . \
+ -verbose:class -Xlog:class+load -cp . \
-Dtest.classes=${TESTCLASSES} \
Starter cross
# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \
--- a/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh Sat May 14 09:11:07 2016 -0700
@@ -102,7 +102,7 @@
# run test
${TESTJAVA}${FS}bin${FS}java \
${TESTVMOPTS} \
- -verbose:class -Xlog:classload -cp . \
+ -verbose:class -Xlog:class+load -cp . \
-Dtest.classes=${TESTCLASSES} \
Starter one-way
# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/StackWalker/CountLocalSlots.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,61 @@
+/*
+ * 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
+ * @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 + ")");
+ }
+ }
+ }
+}
--- a/jdk/test/java/lang/StackWalker/LocalsAndOperands.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/StackWalker/LocalsAndOperands.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -23,17 +23,20 @@
/*
* @test
- * @bug 8020968
- * @summary Sanity test for locals and operands
- * @run main LocalsAndOperands
+ * @bug 8020968 8147039
+ * @summary Tests for locals and operands
+ * @run testng LocalsAndOperands
*/
+import org.testng.annotations.*;
import java.lang.StackWalker.StackFrame;
import java.lang.reflect.*;
-import java.util.List;
-import java.util.stream.Collectors;
+import java.util.*;
+import java.util.stream.*;
public class LocalsAndOperands {
+ static final boolean debug = true;
+
static Class<?> liveStackFrameClass;
static Class<?> primitiveValueClass;
static StackWalker extendedWalker;
@@ -41,92 +44,319 @@
static Method getOperands;
static Method getMonitors;
static Method primitiveType;
- public static void main(String... args) throws Exception {
- liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
- primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveValue");
+
+ static {
+ try {
+ liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
+ primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveValue");
+
+ getLocals = liveStackFrameClass.getDeclaredMethod("getLocals");
+ getLocals.setAccessible(true);
+
+ getOperands = liveStackFrameClass.getDeclaredMethod("getStack");
+ getOperands.setAccessible(true);
+
+ getMonitors = liveStackFrameClass.getDeclaredMethod("getMonitors");
+ getMonitors.setAccessible(true);
- getLocals = liveStackFrameClass.getDeclaredMethod("getLocals");
- getLocals.setAccessible(true);
+ primitiveType = primitiveValueClass.getDeclaredMethod("type");
+ primitiveType.setAccessible(true);
- getOperands = liveStackFrameClass.getDeclaredMethod("getStack");
- getOperands.setAccessible(true);
+ Method method = liveStackFrameClass.getMethod("getStackWalker");
+ method.setAccessible(true);
+ extendedWalker = (StackWalker) method.invoke(null);
+ } catch (Throwable t) { throw new RuntimeException(t); }
+ }
+
+ /** Helper method to return a StackFrame's locals */
+ static Object[] invokeGetLocals(StackFrame arg) {
+ try {
+ return (Object[]) getLocals.invoke(arg);
+ } catch (Exception e) { throw new RuntimeException(e); }
+ }
- getMonitors = liveStackFrameClass.getDeclaredMethod("getMonitors");
- getMonitors.setAccessible(true);
+ /*****************
+ * DataProviders *
+ *****************/
- primitiveType = primitiveValueClass.getDeclaredMethod("type");
- primitiveType.setAccessible(true);
+ /** Calls testLocals() and provides LiveStackFrames for testLocals* methods */
+ @DataProvider
+ public static StackFrame[][] provider() {
+ return new StackFrame[][] {
+ new Tester().testLocals()
+ };
+ }
- Method method = liveStackFrameClass.getMethod("getStackWalker");
- method.setAccessible(true);
- extendedWalker = (StackWalker) method.invoke(null);
- new LocalsAndOperands(extendedWalker, true).test();
+ /**
+ * 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()
+ };
+ }
- // no access to local and operands.
- new LocalsAndOperands(StackWalker.getInstance(), false).test();
+ /**
+ * 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()
+ };
}
- private final StackWalker walker;
- private final boolean extended;
- LocalsAndOperands(StackWalker walker, boolean extended) {
- this.walker = walker;
- this.extended = extended;
+ /**
+ * 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()
+ };
+ }
+
+ /****************
+ * Test methods *
+ ****************/
+
+ /**
+ * Check for expected local values and types in the LiveStackFrame
+ */
+ @Test(dataProvider = "keepAliveProvider")
+ public static void checkLocalValues(StackFrame... frames) {
+ if (debug) {
+ System.out.println("Running checkLocalValues");
+ dumpStackWithLocals(frames);
+ }
+ Arrays.stream(frames).filter(f -> f.getMethodName()
+ .equals("testLocalsKeepAlive"))
+ .forEach(
+ f -> {
+ Object[] locals = invokeGetLocals(f);
+ for (int i = 0; i < locals.length; i++) {
+ // Value
+ String expected = Tester.LOCAL_VALUES[i];
+ Object observed = locals[i];
+ if (expected != null /* skip nulls in golden values */ &&
+ !expected.equals(observed.toString())) {
+ System.err.println("Local value mismatch:");
+ if (!debug) { dumpStackWithLocals(frames); }
+ throw new RuntimeException("local " + i + " value is " +
+ observed + ", expected " + expected);
+ }
+
+ // Type
+ expected = Tester.LOCAL_TYPES[i];
+ observed = type(locals[i]);
+ if (expected != null /* skip nulls in golden values */ &&
+ !expected.equals(observed)) {
+ System.err.println("Local type mismatch:");
+ if (!debug) { dumpStackWithLocals(frames); }
+ throw new RuntimeException("local " + i + " type is " +
+ observed + ", expected " + expected);
+ }
+ }
+ }
+ );
+ }
+
+ /**
+ * Basic sanity check for locals and operands
+ */
+ @Test(dataProvider = "provider")
+ public static void sanityCheck(StackFrame... frames) {
+ if (debug) {
+ System.out.println("Running sanityCheck");
+ }
+ try {
+ Stream<StackFrame> stream = Arrays.stream(frames);
+ if (debug) {
+ stream.forEach(LocalsAndOperands::printLocals);
+ } else {
+ System.out.println(stream.count() + " frames");
+ }
+ } catch (Throwable t) {
+ dumpStackWithLocals(frames);
+ throw t;
+ }
}
- synchronized void test() throws Exception {
- int x = 10;
- char c = 'z';
- String hi = "himom";
- long l = 1000000L;
- double d = 3.1415926;
-
- List<StackWalker.StackFrame> frames = walker.walk(s -> s.collect(Collectors.toList()));
- if (extended) {
- for (StackWalker.StackFrame f : frames) {
- System.out.println("frame: " + f);
- Object[] locals = (Object[]) getLocals.invoke(f);
- for (int i = 0; i < locals.length; i++) {
- System.out.format(" local %d: %s type %s\n", i, locals[i], type(locals[i]));
+ /**
+ * Sanity check for locals and operands, including testng/jtreg frames
+ */
+ @Test(dataProvider = "unfilteredProvider")
+ public static void unfilteredSanityCheck(StackFrame... frames) {
+ if (debug) {
+ System.out.println("Running unfilteredSanityCheck");
+ }
+ try {
+ Stream<StackFrame> stream = Arrays.stream(frames);
+ if (debug) {
+ stream.forEach(f -> { System.out.println(f + ": " +
+ invokeGetLocals(f).length + " locals"); } );
+ } else {
+ System.out.println(stream.count() + " frames");
+ }
+ } catch (Throwable t) {
+ dumpStackWithLocals(frames);
+ throw t;
+ }
+ }
- // check for non-null locals in LocalsAndOperands.test()
- if (f.getClassName().equals("LocalsAndOperands") &&
- f.getMethodName().equals("test")) {
- if (locals[i] == null) {
- throw new RuntimeException("kept-alive locals should not be null");
- }
- }
- }
+ /**
+ * Test that LiveStackFrames are not provided with the default StackWalker
+ * options.
+ */
+ @Test(dataProvider = "noLocalsProvider")
+ public static void withoutLocalsAndOperands(StackFrame... frames) {
+ for (StackFrame frame : frames) {
+ if (liveStackFrameClass.isInstance(frame)) {
+ throw new RuntimeException("should not be LiveStackFrame");
+ }
+ }
+ }
+
+ static class Tester {
+ private StackWalker walker;
+ private boolean filter = true; // Filter out testng/jtreg/etc frames?
+
+ Tester() {
+ this.walker = extendedWalker;
+ }
- Object[] operands = (Object[]) getOperands.invoke(f);
- for (int i = 0; i < operands.length; i++) {
- System.out.format(" operand %d: %s type %s%n", i, operands[i],
- type(operands[i]));
- }
+ Tester(StackWalker walker, boolean filter) {
+ this.walker = walker;
+ this.filter = filter;
+ }
- Object[] monitors = (Object[]) getMonitors.invoke(f);
- for (int i = 0; i < monitors.length; i++) {
- System.out.format(" monitor %d: %s%n", i, monitors[i]);
- }
- }
- } else {
- for (StackFrame f : frames) {
- if (liveStackFrameClass.isInstance(f)) {
- throw new RuntimeException("should not be LiveStackFrame");
- }
+ /**
+ * Perform stackwalk without keeping local variables alive and return an
+ * array of the collected StackFrames
+ */
+ private synchronized StackFrame[] testLocals() {
+ // Unused local variables will become dead
+ int x = 10;
+ char c = 'z';
+ String hi = "himom";
+ long l = 1000000L;
+ double d = 3.1415926;
+
+ if (filter) {
+ return walker.walk(s -> s.filter(f -> TEST_METHODS.contains(f
+ .getMethodName())).collect(Collectors.toList()))
+ .toArray(new StackFrame[0]);
+ } else {
+ return walker.walk(s -> s.collect(Collectors.toList()))
+ .toArray(new StackFrame[0]);
}
}
- // Use local variables so they stay alive
- System.out.println("Stayin' alive: "+x+" "+c+" "+hi+" "+l+" "+d);
+
+ /**
+ * Perform stackwalk, keeping local variables alive, and return a list of
+ * the collected StackFrames
+ */
+ private synchronized StackFrame[] testLocalsKeepAlive() {
+ int x = 10;
+ char c = 'z';
+ String hi = "himom";
+ long l = 1000000L;
+ double d = 3.1415926;
+
+ List<StackWalker.StackFrame> frames;
+ if (filter) {
+ frames = walker.walk(s -> s.filter(f -> TEST_METHODS.contains(f
+ .getMethodName())).collect(Collectors.toList()));
+ } else {
+ frames = walker.walk(s -> s.collect(Collectors.toList()));
+ }
+
+ // Use local variables so they stay alive
+ System.out.println("Stayin' alive: "+x+" "+c+" "+hi+" "+l+" "+d);
+ return frames.toArray(new StackFrame[0]); // FIXME: convert to Array here
+ }
+
+ // Expected values for locals in testLocals() & testLocalsKeepAlive()
+ // TODO: use real values instead of Strings, rebuild doubles & floats, etc
+ private final static String[] LOCAL_VALUES = new String[] {
+ null, // skip, LocalsAndOperands$Tester@XXX identity is different each run
+ "10",
+ "122",
+ "himom",
+ "0",
+ null, // skip, fix in 8156073
+ null, // skip, fix in 8156073
+ null, // skip, fix in 8156073
+ "0"
+ };
+
+ // Expected types for locals in testLocals() & testLocalsKeepAlive()
+ // TODO: use real types
+ private final static String[] LOCAL_TYPES = new String[] {
+ null, // skip
+ "I",
+ "I",
+ "java.lang.String",
+ "I",
+ "I",
+ "I",
+ "I",
+ "I"
+ };
+
+ final static Map NUM_LOCALS = Map.of("testLocals", 8,
+ "testLocalsKeepAlive",
+ LOCAL_VALUES.length);
+ private final static Collection<String> TEST_METHODS = NUM_LOCALS.keySet();
}
- String type(Object o) throws Exception {
- if (o == null) {
- return "null";
- } else if (primitiveValueClass.isInstance(o)) {
- char c = (char)primitiveType.invoke(o);
- return String.valueOf(c);
- } else {
- return o.getClass().getName();
- }
+ /**
+ * Print stack trace with locals
+ */
+ public static void dumpStackWithLocals(StackFrame...frames) {
+ Arrays.stream(frames).forEach(LocalsAndOperands::printLocals);
+ }
+
+ /**
+ * Print the StackFrame and an indexed list of its locals
+ */
+ public static void printLocals(StackWalker.StackFrame frame) {
+ try {
+ System.out.println(frame);
+ Object[] locals = (Object[]) getLocals.invoke(frame);
+ for (int i = 0; i < locals.length; i++) {
+ System.out.format(" local %d: %s type %s\n", i, locals[i], type(locals[i]));
+ }
+
+ Object[] operands = (Object[]) getOperands.invoke(frame);
+ for (int i = 0; i < operands.length; i++) {
+ System.out.format(" operand %d: %s type %s%n", i, operands[i],
+ type(operands[i]));
+ }
+
+ Object[] monitors = (Object[]) getMonitors.invoke(frame);
+ for (int i = 0; i < monitors.length; i++) {
+ System.out.format(" monitor %d: %s%n", i, monitors[i]);
+ }
+ } catch (Exception e) { throw new RuntimeException(e); }
+ }
+
+ private static String type(Object o) {
+ try {
+ if (o == null) {
+ return "null";
+ } else if (primitiveValueClass.isInstance(o)) {
+ char c = (char)primitiveType.invoke(o);
+ return String.valueOf(c);
+ } else {
+ return o.getClass().getName();
+ }
+ } catch(Exception e) { throw new RuntimeException(e); }
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/StackWalker/LocalsCrash.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,74 @@
+/*
+ * 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 Test for -Xcomp crash that happened before 8147039 fix
+ * @run testng/othervm -Xcomp LocalsCrash
+ */
+
+import org.testng.annotations.*;
+import java.lang.reflect.*;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class LocalsCrash {
+ static Class<?> liveStackFrameClass;
+ static Method getStackWalker;
+
+ static {
+ try {
+ liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
+ getStackWalker = liveStackFrameClass.getMethod("getStackWalker");
+ getStackWalker.setAccessible(true);
+ } catch (Throwable t) { throw new RuntimeException(t); }
+ }
+
+ private StackWalker walker;
+
+ LocalsCrash() {
+ try {
+ walker = (StackWalker) getStackWalker.invoke(null);
+ } catch (Exception e) { throw new RuntimeException(e); }
+ }
+
+ @Test
+ public void test00() { doStackWalk(); }
+
+ @Test
+ public void test01() { doStackWalk(); }
+
+ private synchronized List<StackWalker.StackFrame> doStackWalk() {
+ try {
+ // Unused local variables will become dead
+ int x = 10;
+ char c = 'z';
+ String hi = "himom";
+ long l = 1000000L;
+ double d = 3.1415926;
+
+ return walker.walk(s -> s.collect(Collectors.toList()));
+ } catch (Exception e) { throw new RuntimeException(e); }
+ }
+}
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh Sat May 14 09:11:07 2016 -0700
@@ -80,5 +80,5 @@
# Finally we run the test
(cd "${TESTCLASSES}"; \
- $JAVA ${TESTVMOPTS} -Xverify:none -Xlog:classunload \
+ $JAVA ${TESTVMOPTS} -Xverify:none -Xlog:class+unload \
-javaagent:ClassUnloadTest.jar ClassUnloadTest "${OTHERDIR}" Bar.jar)
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleBaseTest.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleBaseTest.java Sat May 14 09:11:07 2016 -0700
@@ -40,6 +40,7 @@
abstract class VarHandleBaseTest {
static final int ITERS = Integer.getInteger("iters", 1);
+ static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
interface ThrowingRunnable {
void run() throws Throwable;
@@ -475,4 +476,4 @@
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
}
}
-}
\ No newline at end of file
+}
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java Sat May 14 09:11:07 2016 -0700
@@ -104,7 +104,6 @@
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
- assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
@@ -402,39 +401,41 @@
}
{
- boolean r = vh.weakCompareAndSet(recv, 1, 2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(recv);
assertEquals(x, 2, "weakCompareAndSet int value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(recv, 2, 1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, 2, 1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(recv);
assertEquals(x, 1, "weakCompareAndSetAcquire int");
}
{
- boolean r = vh.weakCompareAndSetRelease(recv, 1, 2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(recv);
assertEquals(x, 2, "weakCompareAndSetRelease int");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(recv, 2, 1);
- assertEquals(r, true, "weakCompareAndSetVolatile int");
- int x = (int) vh.get(recv);
- assertEquals(x, 1, "weakCompareAndSetVolatile int value");
- }
-
// Compare set and get
{
- int o = (int) vh.getAndSet(recv, 2);
- assertEquals(o, 1, "getAndSet int");
+ int o = (int) vh.getAndSet(recv, 1);
+ assertEquals(o, 2, "getAndSet int");
int x = (int) vh.get(recv);
- assertEquals(x, 2, "getAndSet int value");
+ assertEquals(x, 1, "getAndSet int value");
}
vh.set(recv, 1);
@@ -543,39 +544,41 @@
}
{
- boolean r = (boolean) vh.weakCompareAndSet(1, 2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get();
assertEquals(x, 2, "weakCompareAndSet int value");
}
{
- boolean r = (boolean) vh.weakCompareAndSetAcquire(2, 1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(2, 1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get();
assertEquals(x, 1, "weakCompareAndSetAcquire int");
}
{
- boolean r = (boolean) vh.weakCompareAndSetRelease(1, 2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get();
assertEquals(x, 2, "weakCompareAndSetRelease int");
}
- {
- boolean r = (boolean) vh.weakCompareAndSetVolatile(2, 1);
- assertEquals(r, true, "weakCompareAndSetVolatile int");
- int x = (int) vh.get();
- assertEquals(x, 1, "weakCompareAndSetVolatile int value");
- }
-
// Compare set and get
{
- int o = (int) vh.getAndSet( 2);
- assertEquals(o, 1, "getAndSet int");
+ int o = (int) vh.getAndSet( 1);
+ assertEquals(o, 2, "getAndSet int");
int x = (int) vh.get();
- assertEquals(x, 2, "getAndSet int value");
+ assertEquals(x, 1, "getAndSet int value");
}
vh.set(1);
@@ -687,39 +690,41 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, 1, 2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, 2, "weakCompareAndSet int value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, 2, 1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, 2, 1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, 1, "weakCompareAndSetAcquire int");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, 1, 2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, 2, "weakCompareAndSetRelease int");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(array, i, 2, 1);
- assertEquals(r, true, "weakCompareAndSetVolatile int");
- int x = (int) vh.get(array, i);
- assertEquals(x, 1, "weakCompareAndSetVolatile int value");
- }
-
// Compare set and get
{
- int o = (int) vh.getAndSet(array, i, 2);
- assertEquals(o, 1, "getAndSet int");
+ int o = (int) vh.getAndSet(array, i, 1);
+ assertEquals(o, 2, "getAndSet int");
int x = (int) vh.get(array, i);
- assertEquals(x, 2, "getAndSet int value");
+ assertEquals(x, 1, "getAndSet int value");
}
vh.set(array, i, 1);
@@ -800,10 +805,6 @@
});
checkIOOBE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(array, ci, 1, 2);
- });
-
- checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, 1, 2);
});
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java Sat May 14 09:11:07 2016 -0700
@@ -104,7 +104,6 @@
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
- assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
@@ -402,39 +401,41 @@
}
{
- boolean r = vh.weakCompareAndSet(recv, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(recv);
assertEquals(x, 2L, "weakCompareAndSet long value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(recv, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, 2L, 1L);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(recv);
assertEquals(x, 1L, "weakCompareAndSetAcquire long");
}
{
- boolean r = vh.weakCompareAndSetRelease(recv, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(recv);
assertEquals(x, 2L, "weakCompareAndSetRelease long");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(recv, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetVolatile long");
- long x = (long) vh.get(recv);
- assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
- }
-
// Compare set and get
{
- long o = (long) vh.getAndSet(recv, 2L);
- assertEquals(o, 1L, "getAndSet long");
+ long o = (long) vh.getAndSet(recv, 1L);
+ assertEquals(o, 2L, "getAndSet long");
long x = (long) vh.get(recv);
- assertEquals(x, 2L, "getAndSet long value");
+ assertEquals(x, 1L, "getAndSet long value");
}
vh.set(recv, 1L);
@@ -543,39 +544,41 @@
}
{
- boolean r = (boolean) vh.weakCompareAndSet(1L, 2L);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get();
assertEquals(x, 2L, "weakCompareAndSet long value");
}
{
- boolean r = (boolean) vh.weakCompareAndSetAcquire(2L, 1L);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(2L, 1L);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get();
assertEquals(x, 1L, "weakCompareAndSetAcquire long");
}
{
- boolean r = (boolean) vh.weakCompareAndSetRelease(1L, 2L);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get();
assertEquals(x, 2L, "weakCompareAndSetRelease long");
}
- {
- boolean r = (boolean) vh.weakCompareAndSetVolatile(2L, 1L);
- assertEquals(r, true, "weakCompareAndSetVolatile long");
- long x = (long) vh.get();
- assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
- }
-
// Compare set and get
{
- long o = (long) vh.getAndSet( 2L);
- assertEquals(o, 1L, "getAndSet long");
+ long o = (long) vh.getAndSet( 1L);
+ assertEquals(o, 2L, "getAndSet long");
long x = (long) vh.get();
- assertEquals(x, 2L, "getAndSet long value");
+ assertEquals(x, 1L, "getAndSet long value");
}
vh.set(1L);
@@ -687,39 +690,41 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, 2L, "weakCompareAndSet long value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, 2L, 1L);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, 1L, "weakCompareAndSetAcquire long");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, 2L, "weakCompareAndSetRelease long");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(array, i, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetVolatile long");
- long x = (long) vh.get(array, i);
- assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
- }
-
// Compare set and get
{
- long o = (long) vh.getAndSet(array, i, 2L);
- assertEquals(o, 1L, "getAndSet long");
+ long o = (long) vh.getAndSet(array, i, 1L);
+ assertEquals(o, 2L, "getAndSet long");
long x = (long) vh.get(array, i);
- assertEquals(x, 2L, "getAndSet long value");
+ assertEquals(x, 1L, "getAndSet long value");
}
vh.set(array, i, 1L);
@@ -800,10 +805,6 @@
});
checkIOOBE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(array, ci, 1L, 2L);
- });
-
- checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, 1L, 2L);
});
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessString.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessString.java Sat May 14 09:11:07 2016 -0700
@@ -104,7 +104,6 @@
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
- assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
@@ -416,39 +415,41 @@
}
{
- boolean r = vh.weakCompareAndSet(recv, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSet String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "weakCompareAndSet String value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(recv, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetAcquire String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "weakCompareAndSetAcquire String");
}
{
- boolean r = vh.weakCompareAndSetRelease(recv, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSetRelease String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "weakCompareAndSetRelease String");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(recv, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetVolatile String");
- String x = (String) vh.get(recv);
- assertEquals(x, "foo", "weakCompareAndSetVolatile String value");
- }
-
// Compare set and get
{
- String o = (String) vh.getAndSet(recv, "bar");
- assertEquals(o, "foo", "getAndSet String");
+ String o = (String) vh.getAndSet(recv, "foo");
+ assertEquals(o, "bar", "getAndSet String");
String x = (String) vh.get(recv);
- assertEquals(x, "bar", "getAndSet String value");
+ assertEquals(x, "foo", "getAndSet String value");
}
}
@@ -555,39 +556,41 @@
}
{
- boolean r = (boolean) vh.weakCompareAndSet("foo", "bar");
- assertEquals(r, true, "weakCompareAndSet String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
String x = (String) vh.get();
assertEquals(x, "bar", "weakCompareAndSet String value");
}
{
- boolean r = (boolean) vh.weakCompareAndSetAcquire("bar", "foo");
- assertEquals(r, true, "weakCompareAndSetAcquire String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire("bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
String x = (String) vh.get();
assertEquals(x, "foo", "weakCompareAndSetAcquire String");
}
{
- boolean r = (boolean) vh.weakCompareAndSetRelease("foo", "bar");
- assertEquals(r, true, "weakCompareAndSetRelease String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
String x = (String) vh.get();
assertEquals(x, "bar", "weakCompareAndSetRelease String");
}
- {
- boolean r = (boolean) vh.weakCompareAndSetVolatile("bar", "foo");
- assertEquals(r, true, "weakCompareAndSetVolatile String");
- String x = (String) vh.get();
- assertEquals(x, "foo", "weakCompareAndSetVolatile String value");
- }
-
// Compare set and get
{
- String o = (String) vh.getAndSet( "bar");
- assertEquals(o, "foo", "getAndSet String");
+ String o = (String) vh.getAndSet( "foo");
+ assertEquals(o, "bar", "getAndSet String");
String x = (String) vh.get();
- assertEquals(x, "bar", "getAndSet String value");
+ assertEquals(x, "foo", "getAndSet String value");
}
}
@@ -697,39 +700,41 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSet String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "weakCompareAndSet String value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetAcquire String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "weakCompareAndSetAcquire String");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSetRelease String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "weakCompareAndSetRelease String");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(array, i, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetVolatile String");
- String x = (String) vh.get(array, i);
- assertEquals(x, "foo", "weakCompareAndSetVolatile String value");
- }
-
// Compare set and get
{
- String o = (String) vh.getAndSet(array, i, "bar");
- assertEquals(o, "foo", "getAndSet String");
+ String o = (String) vh.getAndSet(array, i, "foo");
+ assertEquals(o, "bar", "getAndSet String");
String x = (String) vh.get(array, i);
- assertEquals(x, "bar", "getAndSet String value");
+ assertEquals(x, "foo", "getAndSet String value");
}
}
@@ -808,10 +813,6 @@
});
checkIOOBE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(array, ci, "foo", "bar");
- });
-
- checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, "foo", "bar");
});
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java Sat May 14 09:11:07 2016 -0700
@@ -700,22 +700,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet double");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet double value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire double");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire double");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease double");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease double");
}
@@ -840,22 +849,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet double");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet double value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire double");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire double");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease double");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease double");
}
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java Sat May 14 09:11:07 2016 -0700
@@ -700,22 +700,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet float");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet float value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire float");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire float");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease float");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease float");
}
@@ -840,22 +849,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet float");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet float value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire float");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire float");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease float");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease float");
}
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java Sat May 14 09:11:07 2016 -0700
@@ -714,22 +714,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet int value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire int");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease int");
}
@@ -863,22 +872,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet int value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire int");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease int");
}
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java Sat May 14 09:11:07 2016 -0700
@@ -714,22 +714,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet long value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire long");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease long");
}
@@ -863,22 +872,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet long value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire long");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease long");
}
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java Sat May 14 09:11:07 2016 -0700
@@ -208,39 +208,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1, 2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "weakCompareAndSet int value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2, 1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2, 1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "weakCompareAndSetAcquire int");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1, 2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "weakCompareAndSetRelease int");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2, 1);
- assertEquals(r, true, "weakCompareAndSetVolatile int");
- int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, 1, "weakCompareAndSetVolatile int value");
- }
-
// Compare set and get
{
- int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2);
- assertEquals(o, 1, "getAndSet int");
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 1);
+ assertEquals(o, 2, "getAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, 2, "getAndSet int value");
+ assertEquals(x, 1, "getAndSet int value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, 1);
@@ -349,39 +351,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1, 2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "weakCompareAndSet int value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2, 1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2, 1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "weakCompareAndSetAcquire int");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1, 2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "weakCompareAndSetRelease int");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2, 1);
- assertEquals(r, true, "weakCompareAndSetVolatile int");
- int x = (int) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, 1, "weakCompareAndSetVolatile int value");
- }
-
// Compare set and get
{
- int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2);
- assertEquals(o, 1, "getAndSet int");
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 1);
+ assertEquals(o, 2, "getAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, 2, "getAndSet int value");
+ assertEquals(x, 1, "getAndSet int value");
}
hs.get(TestAccessMode.SET).invokeExact(1);
@@ -493,39 +497,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1, 2);
- assertEquals(r, true, "weakCompareAndSet int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "weakCompareAndSet int value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2, 1);
- assertEquals(r, true, "weakCompareAndSetAcquire int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2, 1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "weakCompareAndSetAcquire int");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1, 2);
- assertEquals(r, true, "weakCompareAndSetRelease int");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1, 2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "weakCompareAndSetRelease int");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2, 1);
- assertEquals(r, true, "weakCompareAndSetVolatile int");
- int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, 1, "weakCompareAndSetVolatile int value");
- }
-
// Compare set and get
{
- int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2);
- assertEquals(o, 1, "getAndSet int");
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 1);
+ assertEquals(o, 2, "getAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, 2, "getAndSet int value");
+ assertEquals(x, 1, "getAndSet int value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, 1);
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java Sat May 14 09:11:07 2016 -0700
@@ -208,39 +208,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "weakCompareAndSet long value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2L, 1L);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "weakCompareAndSetAcquire long");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "weakCompareAndSetRelease long");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetVolatile long");
- long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
- }
-
// Compare set and get
{
- long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2L);
- assertEquals(o, 1L, "getAndSet long");
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 1L);
+ assertEquals(o, 2L, "getAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, 2L, "getAndSet long value");
+ assertEquals(x, 1L, "getAndSet long value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, 1L);
@@ -349,39 +351,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1L, 2L);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "weakCompareAndSet long value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2L, 1L);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2L, 1L);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "weakCompareAndSetAcquire long");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1L, 2L);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "weakCompareAndSetRelease long");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2L, 1L);
- assertEquals(r, true, "weakCompareAndSetVolatile long");
- long x = (long) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
- }
-
// Compare set and get
{
- long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2L);
- assertEquals(o, 1L, "getAndSet long");
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 1L);
+ assertEquals(o, 2L, "getAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, 2L, "getAndSet long value");
+ assertEquals(x, 1L, "getAndSet long value");
}
hs.get(TestAccessMode.SET).invokeExact(1L);
@@ -493,39 +497,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSet long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "weakCompareAndSet long value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetAcquire long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2L, 1L);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "weakCompareAndSetAcquire long");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1L, 2L);
- assertEquals(r, true, "weakCompareAndSetRelease long");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1L, 2L);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "weakCompareAndSetRelease long");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2L, 1L);
- assertEquals(r, true, "weakCompareAndSetVolatile long");
- long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
- }
-
// Compare set and get
{
- long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2L);
- assertEquals(o, 1L, "getAndSet long");
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 1L);
+ assertEquals(o, 2L, "getAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, 2L, "getAndSet long value");
+ assertEquals(x, 1L, "getAndSet long value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L);
--- a/jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java Sat May 14 09:11:07 2016 -0700
@@ -208,39 +208,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSet String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "weakCompareAndSet String value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetAcquire String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "weakCompareAndSetAcquire String");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSetRelease String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "weakCompareAndSetRelease String");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetVolatile String");
- String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, "foo", "weakCompareAndSetVolatile String value");
- }
-
// Compare set and get
{
- String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, "bar");
- assertEquals(o, "foo", "getAndSet String");
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, "foo");
+ assertEquals(o, "bar", "getAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, "bar", "getAndSet String value");
+ assertEquals(x, "foo", "getAndSet String value");
}
}
@@ -345,39 +347,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact("foo", "bar");
- assertEquals(r, true, "weakCompareAndSet String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "weakCompareAndSet String value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact("bar", "foo");
- assertEquals(r, true, "weakCompareAndSetAcquire String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact("bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "weakCompareAndSetAcquire String");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact("foo", "bar");
- assertEquals(r, true, "weakCompareAndSetRelease String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "weakCompareAndSetRelease String");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact("bar", "foo");
- assertEquals(r, true, "weakCompareAndSetVolatile String");
- String x = (String) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, "foo", "weakCompareAndSetVolatile String value");
- }
-
// Compare set and get
{
- String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact("bar");
- assertEquals(o, "foo", "getAndSet String");
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact( "foo");
+ assertEquals(o, "bar", "getAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, "bar", "getAndSet String value");
+ assertEquals(x, "foo", "getAndSet String value");
}
}
@@ -485,39 +489,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSet String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "weakCompareAndSet String value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetAcquire String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "weakCompareAndSetAcquire String");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, "foo", "bar");
- assertEquals(r, true, "weakCompareAndSetRelease String");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "weakCompareAndSetRelease String");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, "bar", "foo");
- assertEquals(r, true, "weakCompareAndSetVolatile String");
- String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, "foo", "weakCompareAndSetVolatile String value");
- }
-
// Compare set and get
{
- String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, "bar");
- assertEquals(o, "foo", "getAndSet String");
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, "foo");
+ assertEquals(o, "bar", "getAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, "bar", "getAndSet String value");
+ assertEquals(x, "foo", "getAndSet String value");
}
}
--- a/jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template Sat May 14 09:11:07 2016 -0700
@@ -105,7 +105,6 @@
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
- assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
@@ -115,7 +114,6 @@
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
- assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
@@ -299,10 +297,6 @@
});
checkUOE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(recv, $value1$, $value2$);
- });
-
- checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
});
@@ -389,10 +383,6 @@
});
checkUOE(() -> {
- boolean r = vh.weakCompareAndSetVolatile($value1$, $value2$);
- });
-
- checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
});
@@ -504,39 +494,41 @@
}
{
- boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) vh.get(recv);
assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(recv, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get(recv);
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get(recv);
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(recv, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetVolatile $type$");
- $type$ x = ($type$) vh.get(recv);
- assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
- }
-
// Compare set and get
{
- $type$ o = ($type$) vh.getAndSet(recv, $value2$);
- assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ o = ($type$) vh.getAndSet(recv, $value1$);
+ assertEquals(o, $value2$, "getAndSet $type$");
$type$ x = ($type$) vh.get(recv);
- assertEquals(x, $value2$, "getAndSet $type$ value");
+ assertEquals(x, $value1$, "getAndSet $type$ value");
}
#end[CAS]
@@ -576,10 +568,6 @@
});
checkUOE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(recv, $value1$, $value2$);
- });
-
- checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
});
@@ -691,39 +679,41 @@
}
{
- boolean r = (boolean) vh.weakCompareAndSet($value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) vh.get();
assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
}
{
- boolean r = (boolean) vh.weakCompareAndSetAcquire($value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire($value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get();
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = (boolean) vh.weakCompareAndSetRelease($value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get();
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
}
- {
- boolean r = (boolean) vh.weakCompareAndSetVolatile($value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetVolatile $type$");
- $type$ x = ($type$) vh.get();
- assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
- }
-
// Compare set and get
{
- $type$ o = ($type$) vh.getAndSet( $value2$);
- assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ o = ($type$) vh.getAndSet( $value1$);
+ assertEquals(o, $value2$, "getAndSet $type$");
$type$ x = ($type$) vh.get();
- assertEquals(x, $value2$, "getAndSet $type$ value");
+ assertEquals(x, $value1$, "getAndSet $type$ value");
}
#end[CAS]
@@ -763,10 +753,6 @@
});
checkUOE(() -> {
- boolean r = vh.weakCompareAndSetVolatile($value1$, $value2$);
- });
-
- checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
});
@@ -881,39 +867,41 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
}
- {
- boolean r = vh.weakCompareAndSetVolatile(array, i, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetVolatile $type$");
- $type$ x = ($type$) vh.get(array, i);
- assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
- }
-
// Compare set and get
{
- $type$ o = ($type$) vh.getAndSet(array, i, $value2$);
- assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ o = ($type$) vh.getAndSet(array, i, $value1$);
+ assertEquals(o, $value2$, "getAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
- assertEquals(x, $value2$, "getAndSet $type$ value");
+ assertEquals(x, $value1$, "getAndSet $type$ value");
}
#end[CAS]
@@ -957,10 +945,6 @@
});
checkUOE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(array, i, $value1$, $value2$);
- });
-
- checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, $value1$, $value2$);
});
@@ -1040,10 +1024,6 @@
});
checkIOOBE(() -> {
- boolean r = vh.weakCompareAndSetVolatile(array, ci, $value1$, $value2$);
- });
-
- checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, $value1$, $value2$);
});
--- a/jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template Sat May 14 09:11:07 2016 -0700
@@ -884,22 +884,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet $type$ value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease $type$");
}
@@ -1037,22 +1046,31 @@
}
{
- boolean r = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSet $type$ value");
}
{
- boolean r = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "weakCompareAndSetRelease $type$");
}
--- a/jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template Sat May 14 09:11:07 2016 -0700
@@ -209,39 +209,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetVolatile $type$");
- $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
- }
-
// Compare set and get
{
- $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$);
- assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value1$);
+ assertEquals(o, $value2$, "getAndSet $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
- assertEquals(x, $value2$, "getAndSet $type$ value");
+ assertEquals(x, $value1$, "getAndSet $type$ value");
}
#end[CAS]
@@ -380,39 +382,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact($value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetVolatile $type$");
- $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
- }
-
// Compare set and get
{
- $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact($value2$);
- assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value1$);
+ assertEquals(o, $value2$, "getAndSet $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
- assertEquals(x, $value2$, "getAndSet $type$ value");
+ assertEquals(x, $value1$, "getAndSet $type$ value");
}
#end[CAS]
@@ -554,39 +558,41 @@
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSet $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetAcquire $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
}
{
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$);
- assertEquals(r, true, "weakCompareAndSetRelease $type$");
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
}
- {
- boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, $value2$, $value1$);
- assertEquals(r, true, "weakCompareAndSetVolatile $type$");
- $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
- }
-
// Compare set and get
{
- $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$);
- assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value1$);
+ assertEquals(o, $value2$, "getAndSet $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
- assertEquals(x, $value2$, "getAndSet $type$ value");
+ assertEquals(x, $value1$, "getAndSet $type$ value");
}
#end[CAS]
--- a/jdk/test/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java Sat May 14 09:11:07 2016 -0700
@@ -36,9 +36,13 @@
* @modules jdk.management
* @build jdk.testlibrary.* ResetPeakMemoryUsage MemoryUtil RunUtil
* @run main ResetPeakMemoryUsage
+ * @requires vm.opt.ExplicitGCInvokesConcurrent != "true"
+ * @requires vm.opt.ExplicitGCInvokesConcurrentAndUnloadsClasses != "true"
+ * @requires vm.opt.DisableExplicitGC != "true"
*/
import java.lang.management.*;
+import java.lang.ref.WeakReference;
import java.util.*;
public class ResetPeakMemoryUsage {
@@ -100,6 +104,7 @@
printMemoryUsage(usage0, peak0);
obj = new Object[largeArraySize];
+ WeakReference<Object> weakRef = new WeakReference<>(obj);
MemoryUsage usage1 = mpool.getUsage();
MemoryUsage peak1 = mpool.getPeakUsage();
@@ -124,7 +129,11 @@
// The object is now garbage and do a GC
// memory usage should drop
obj = null;
- mbean.gc();
+
+ //This will cause sure shot GC unlike Runtime.gc() invoked by mbean.gc()
+ while(weakRef.get() != null) {
+ mbean.gc();
+ }
MemoryUsage usage2 = mpool.getUsage();
MemoryUsage peak2 = mpool.getPeakUsage();
--- a/jdk/test/java/util/Objects/CheckIndex.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/util/Objects/CheckIndex.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -23,11 +23,13 @@
/**
* @test
- * @summary IndexOutOfBoundsException check index tests
+ * @summary Objects.checkIndex/jdk.internal.util.Preconditions.checkIndex tests
* @run testng CheckIndex
- * @bug 8135248 8142493
+ * @bug 8135248 8142493 8155794
+ * @modules java.base/jdk.internal.util
*/
+import jdk.internal.util.Preconditions;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -95,7 +97,7 @@
public void testCheckIndex(int index, int length, boolean withinBounds) {
String expectedMessage = withinBounds
? null
- : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
+ : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
apply("checkIndex", List.of(index, length)).getMessage();
BiConsumer<Class<? extends RuntimeException>, IntSupplier> checker = (ec, s) -> {
@@ -117,21 +119,21 @@
};
checker.accept(AssertingOutOfBoundsException.class,
- () -> Objects.checkIndex(index, length,
- assertingOutOfBounds(expectedMessage, "checkIndex", index, length)));
+ () -> Preconditions.checkIndex(index, length,
+ assertingOutOfBounds(expectedMessage, "checkIndex", index, length)));
checker.accept(IndexOutOfBoundsException.class,
- () -> Objects.checkIndex(index, length,
- assertingOutOfBoundsReturnNull("checkIndex", index, length)));
+ () -> Preconditions.checkIndex(index, length,
+ assertingOutOfBoundsReturnNull("checkIndex", index, length)));
checker.accept(IndexOutOfBoundsException.class,
- () -> Objects.checkIndex(index, length, null));
+ () -> Preconditions.checkIndex(index, length, null));
checker.accept(IndexOutOfBoundsException.class,
() -> Objects.checkIndex(index, length));
checker.accept(ArrayIndexOutOfBoundsException.class,
- () -> Objects.checkIndex(index, length,
- Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
+ () -> Preconditions.checkIndex(index, length,
+ Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
checker.accept(StringIndexOutOfBoundsException.class,
- () -> Objects.checkIndex(index, length,
- Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
+ () -> Preconditions.checkIndex(index, length,
+ Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
@@ -157,7 +159,7 @@
public void testCheckFromToIndex(int fromIndex, int toIndex, int length, boolean withinBounds) {
String expectedMessage = withinBounds
? null
- : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
+ : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
apply("checkFromToIndex", List.of(fromIndex, toIndex, length)).getMessage();
BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> {
@@ -179,21 +181,21 @@
};
check.accept(AssertingOutOfBoundsException.class,
- () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
- assertingOutOfBounds(expectedMessage, "checkFromToIndex", fromIndex, toIndex, length)));
+ () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
+ assertingOutOfBounds(expectedMessage, "checkFromToIndex", fromIndex, toIndex, length)));
check.accept(IndexOutOfBoundsException.class,
- () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
- assertingOutOfBoundsReturnNull("checkFromToIndex", fromIndex, toIndex, length)));
+ () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
+ assertingOutOfBoundsReturnNull("checkFromToIndex", fromIndex, toIndex, length)));
check.accept(IndexOutOfBoundsException.class,
- () -> Objects.checkFromToIndex(fromIndex, toIndex, length, null));
+ () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length, null));
check.accept(IndexOutOfBoundsException.class,
() -> Objects.checkFromToIndex(fromIndex, toIndex, length));
check.accept(ArrayIndexOutOfBoundsException.class,
- () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
- Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
+ () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
+ Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
check.accept(StringIndexOutOfBoundsException.class,
- () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
- Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
+ () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
+ Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
@@ -226,7 +228,7 @@
public void testCheckFromIndexSize(int fromIndex, int size, int length, boolean withinBounds) {
String expectedMessage = withinBounds
? null
- : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
+ : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
apply("checkFromIndexSize", List.of(fromIndex, size, length)).getMessage();
BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> {
@@ -248,27 +250,27 @@
};
check.accept(AssertingOutOfBoundsException.class,
- () -> Objects.checkFromIndexSize(fromIndex, size, length,
- assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length)));
+ () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
+ assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length)));
check.accept(IndexOutOfBoundsException.class,
- () -> Objects.checkFromIndexSize(fromIndex, size, length,
- assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length)));
+ () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
+ assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length)));
check.accept(IndexOutOfBoundsException.class,
- () -> Objects.checkFromIndexSize(fromIndex, size, length, null));
+ () -> Preconditions.checkFromIndexSize(fromIndex, size, length, null));
check.accept(IndexOutOfBoundsException.class,
() -> Objects.checkFromIndexSize(fromIndex, size, length));
check.accept(ArrayIndexOutOfBoundsException.class,
- () -> Objects.checkFromIndexSize(fromIndex, size, length,
- Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
+ () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
+ Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
check.accept(StringIndexOutOfBoundsException.class,
- () -> Objects.checkFromIndexSize(fromIndex, size, length,
- Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
+ () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
+ Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
@Test
public void uniqueMessagesForCheckKinds() {
BiFunction<String, List<Integer>, IndexOutOfBoundsException> f =
- Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new);
+ Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new);
List<String> messages = new ArrayList<>();
// Exact arguments
--- a/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -167,7 +167,7 @@
final String childPid,
final String className) {
final String regex =
- "(?m)^ *[0-9]+: +([0-9]+) +[0-9]+ +\\Q"+className+"\\E$";
+ "(?m)^ *[0-9]+: +([0-9]+) +[0-9]+ +\\Q"+className+"\\E(?:$| )";
final Callable<Integer> objectsInUse =
new Callable<Integer>() { public Integer call() {
Integer i = Integer.parseInt(
--- a/jdk/test/sun/tools/jhsdb/BasicLauncherTest.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/sun/tools/jhsdb/BasicLauncherTest.java Sat May 14 09:11:07 2016 -0700
@@ -31,9 +31,12 @@
* @run main BasicLauncherTest
*/
+import static jdk.testlibrary.Asserts.assertTrue;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
@@ -99,7 +102,7 @@
System.out.println("Starting LingeredApp");
try {
- theApp = LingeredApp.startApp();
+ theApp = LingeredApp.startApp(Arrays.asList("-Xmx256m"));
System.out.println("Starting " + toolName + " " + toolArgs.get(0) + " against " + theApp.getPid());
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK(toolName);
@@ -129,6 +132,21 @@
launch(expectedMessage, Arrays.asList(toolArgs));
}
+ public static void testHeapDump() throws IOException {
+ File dump = new File("jhsdb.jmap.dump." +
+ System.currentTimeMillis() + ".hprof");
+ if (dump.exists()) {
+ dump.delete();
+ }
+ dump.deleteOnExit();
+
+ launch("heap written to", "jmap",
+ "--binaryheap", "--dumpfile=" + dump.getAbsolutePath());
+
+ assertTrue(dump.exists() && dump.isFile(),
+ "Could not create dump file " + dump.getAbsolutePath());
+ }
+
public static void main(String[] args)
throws IOException {
@@ -145,6 +163,8 @@
launch("Java System Properties", "jinfo");
launch("java.threads", "jsnap");
+ testHeapDump();
+
// The test throws RuntimeException on error.
// IOException is thrown if LingeredApp can't start because of some bad
// environment condition
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 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
+ * 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.
+ */
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jdk.test.lib.apps.LingeredApp;
+import jdk.testlibrary.Utils;
+import jdk.testlibrary.Platform;
+
+/*
+ * @test
+ * @bug 8042397
+ * @summary Unit test for jmap utility test heap configuration reader
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot
+ * @library /test/lib/share/classes
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.*
+ * @build jdk.test.lib.apps.*
+ * @build JMapHeapConfigTest TmtoolTestScenario
+ * @run main JMapHeapConfigTest
+ */
+public class JMapHeapConfigTest {
+
+ static final String expectedJMapValues[] = {
+ "MinHeapFreeRatio",
+ "MaxHeapFreeRatio",
+ "MaxHeapSize",
+ "NewSize",
+ "MaxNewSize",
+ "OldSize",
+ "NewRatio",
+ "SurvivorRatio",
+ "MetaspaceSize",
+ "CompressedClassSpaceSize",
+ "G1HeapRegionSize"};
+
+ // ignoring MaxMetaspaceSize
+
+ static final String desiredMaxHeapSize = "-Xmx128m";
+
+ private static Map<String, String> parseJMapOutput(List<String> jmapOutput) {
+ Map<String, String> heapConfigMap = new HashMap<String, String>();
+ boolean shouldParse = false;
+
+ for (String line : jmapOutput) {
+ line = line.trim();
+
+ if (line.startsWith("Heap Configuration:")) {
+ shouldParse = true;
+ continue;
+ }
+
+ if (line.startsWith("Heap Usage:")) {
+ shouldParse = false;
+ continue;
+ }
+
+ if (shouldParse && !line.equals("")) {
+ String[] lv = line.split("\\s+");
+ try {
+ heapConfigMap.put(lv[0], lv[2]);
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ // Ignore mailformed lines
+ }
+ }
+ }
+ return heapConfigMap;
+ }
+
+ // Compare stored values
+ private static void compareValues(Map<String, String> parsedJMapOutput, Map<String, String> parsedVmOutput) {
+ for (String key : expectedJMapValues) {
+ try {
+ String jmapVal = parsedJMapOutput.get(key);
+ if (jmapVal == null) {
+ throw new RuntimeException("Key '" + key + "' doesn't exists in jmap output");
+ }
+
+ String vmVal = parsedVmOutput.get(key);
+ if (vmVal == null) {
+ throw new RuntimeException("Key '" + key + "' doesn't exists in vm output");
+ }
+
+ if (new BigDecimal(jmapVal).compareTo(new BigDecimal(vmVal)) != 0) {
+ throw new RuntimeException(String.format("Key %s doesn't match %s vs %s", key, vmVal, jmapVal));
+ }
+ } catch (NumberFormatException ex) {
+ throw new RuntimeException("Unexpected key '" + key + "' value", ex);
+ }
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Starting JMapHeapConfigTest");
+
+ if (!Platform.shouldSAAttach()) {
+ // Silently skip the test if we don't have enough permissions to attach
+ System.err.println("Error! Insufficient permissions to attach.");
+ return;
+ }
+
+ if (!LingeredApp.isLastModifiedWorking()) {
+ // Exact behaviour of the test depends to operating system and the test nature,
+ // so just print the warning and continue
+ System.err.println("Warning! Last modified time doesn't work.");
+ }
+
+ boolean mx_found = false;
+ List<String> jvmOptions = Utils.getVmOptions();
+ for (String option : jvmOptions) {
+ if (option.startsWith("-Xmx")) {
+ System.out.println("INFO: maximum heap size set by JTREG as " + option);
+ mx_found = true;
+ break;
+ }
+ }
+
+ // Forward vm options to LingeredApp
+ ArrayList<String> cmd = new ArrayList();
+ cmd.addAll(Utils.getVmOptions());
+ if (!mx_found) {
+ cmd.add(desiredMaxHeapSize);
+ System.out.println("INFO: maximum heap size set explicitly as " + desiredMaxHeapSize);
+ }
+ cmd.add("-XX:+PrintFlagsFinal");
+
+ TmtoolTestScenario tmt = TmtoolTestScenario.create("jmap", "--heap");
+ int exitcode = tmt.launch(cmd);
+ if (exitcode != 0) {
+ throw new RuntimeException("Test FAILED jmap exits with non zero exit code " + exitcode);
+ }
+
+ Map<String,String> parsedJmapOutput = parseJMapOutput(tmt.getToolOutput());
+ Map<String,String> parsedVMOutput = tmt.parseFlagsFinal();
+
+ compareValues(parsedJmapOutput, parsedVMOutput);
+
+ // If test fails it throws RuntimeException
+ System.out.println("Test PASSED");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/tools/jhsdb/heapconfig/TmtoolTestScenario.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 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
+ * 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.
+ */
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import jdk.test.lib.apps.LingeredApp;
+import jdk.testlibrary.JDKToolLauncher;
+import jdk.testlibrary.Utils;
+
+public class TmtoolTestScenario {
+
+ private final ArrayList<String> toolOutput = new ArrayList<String>();
+ private LingeredApp theApp = null;
+ private final String toolName;
+ private final String[] toolArgs;
+
+ /**
+ * @param toolName - name of tool to test
+ * @param toolArgs - tool arguments
+ * @return the object
+ */
+ public static TmtoolTestScenario create(String toolName, String... toolArgs) {
+ return new TmtoolTestScenario(toolName, toolArgs);
+ }
+
+ /**
+ * @return STDOUT of tool
+ */
+ public List<String> getToolOutput() {
+ return toolOutput;
+ }
+
+ /**
+ *
+ * @return STDOUT of test app
+ */
+ public List<String> getAppOutput() {
+ return theApp.getAppOutput();
+ }
+
+ /**
+ * @return Value of the app output with -XX:+PrintFlagsFinal as a map.
+ */
+ public Map<String, String> parseFlagsFinal() {
+ List<String> astr = theApp.getAppOutput();
+ Map<String, String> vmMap = new HashMap<String, String>();
+
+ for (String line : astr) {
+ String[] lv = line.trim().split("\\s+");
+ try {
+ vmMap.put(lv[1], lv[3]);
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ // ignore mailformed lines
+ }
+ }
+ return vmMap;
+ }
+
+ /**
+ *
+ * @param vmArgs - vm and java arguments to launch test app
+ * @return exit code of tool
+ */
+ public int launch(List<String> vmArgs) {
+ System.out.println("Starting LingeredApp");
+ try {
+ try {
+ List<String> vmArgsExtended = new ArrayList<String>();
+ vmArgsExtended.add("-XX:+UsePerfData");
+ vmArgsExtended.addAll(vmArgs);
+ theApp = LingeredApp.startApp(vmArgsExtended);
+
+ System.out.println("Starting " + toolName + " against " + theApp.getPid());
+ JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+ launcher.addToolArg(toolName);
+
+ for (String cmd : toolArgs) {
+ launcher.addToolArg(cmd);
+ }
+ launcher.addToolArg("--pid");
+ launcher.addToolArg(Long.toString(theApp.getPid()));
+
+ ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
+ processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
+ Process toolProcess = processBuilder.start();
+
+ // By default child process output stream redirected to pipe, so we are reading it in foreground.
+ BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
+
+ String line;
+ while ((line = reader.readLine()) != null) {
+ toolOutput.add(line.trim());
+ }
+
+ toolProcess.waitFor();
+
+ return toolProcess.exitValue();
+ } finally {
+ LingeredApp.stopApp(theApp);
+ }
+ } catch (IOException | InterruptedException ex) {
+ throw new RuntimeException("Test ERROR " + ex, ex);
+ }
+ }
+
+ public void launch(String... appArgs) throws IOException {
+ launch(Arrays.asList(appArgs));
+ }
+
+ private TmtoolTestScenario(String toolName, String[] toolArgs) {
+ this.toolName = toolName;
+ this.toolArgs = toolArgs;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/tools/jinfo/BasicJInfoTest.java Sat May 14 09:11:07 2016 -0700
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2005, 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.
+ */
+
+import java.util.Arrays;
+
+import jdk.testlibrary.JDKToolLauncher;
+import jdk.testlibrary.OutputAnalyzer;
+import jdk.testlibrary.ProcessTools;
+
+/*
+ * @test
+ * @summary Unit test for jinfo utility
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.*
+ * @run main BasicJInfoTest
+ */
+public class BasicJInfoTest {
+
+ private static ProcessBuilder processBuilder = new ProcessBuilder();
+
+ public static void main(String[] args) throws Exception {
+ testJinfoNoArgs();
+ testJinfoFlags();
+ testJinfoProps();
+ testJinfoFlagInvalid();
+ }
+
+ private static void testJinfoNoArgs() throws Exception {
+ OutputAnalyzer output = jinfo();
+ output.shouldContain("-XX");
+ output.shouldContain("test.jdk=");
+ output.shouldHaveExitValue(0);
+ }
+
+ private static void testJinfoFlagInvalid() throws Exception {
+ OutputAnalyzer output = jinfo("-flag");
+ output.shouldHaveExitValue(1);
+ }
+
+ private static void testJinfoFlags() throws Exception {
+ OutputAnalyzer output = jinfo("-flags");
+ output.shouldContain("-XX");
+ output.shouldHaveExitValue(0);
+ }
+
+ private static void testJinfoProps() throws Exception {
+ OutputAnalyzer output = jinfo("-props");
+ output.shouldContain("test.jdk=");
+ output.shouldHaveExitValue(0);
+ }
+
+ private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
+ JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
+ if (toolArgs != null) {
+ for (String toolArg : toolArgs) {
+ launcher.addToolArg(toolArg);
+ }
+ }
+ launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
+
+ processBuilder.command(launcher.getCommand());
+ System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
+ OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
+ System.out.println(output.getOutput());
+
+ return output;
+ }
+
+}
--- a/jdk/test/sun/tools/jinfo/JInfoHelper.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * 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.
- */
-
-import java.util.Arrays;
-
-import jdk.testlibrary.JDKToolLauncher;
-import jdk.testlibrary.OutputAnalyzer;
-import jdk.testlibrary.ProcessTools;
-
-/**
- * The helper class for running jinfo utility.
- */
-public final class JInfoHelper {
-
- /**
- * Print configuration information for the current process
- *
- * @param toolArgs List of jinfo options
- */
- public static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
- return jinfo(true, toolArgs);
- }
-
- /**
- * Print usage information
- *
- * @param toolArgs List of jinfo options
- */
- public static OutputAnalyzer jinfoNoPid(String... toolArgs) throws Exception {
- return jinfo(false, toolArgs);
- }
-
- private static OutputAnalyzer jinfo(boolean toPid, String... toolArgs) throws Exception {
- JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
- if (toolArgs != null) {
- for (String toolArg : toolArgs) {
- launcher.addToolArg(toolArg);
- }
- }
- if (toPid) {
- launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
- }
-
- ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
- System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
- OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
- System.out.println(output.getOutput());
-
- return output;
- }
-
-}
--- a/jdk/test/sun/tools/jinfo/JInfoLauncherTest.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) 2014, 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.
- */
-
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeClass;
-import sun.tools.jinfo.JInfo;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-
-import static org.testng.Assert.*;
-
-/**
- * @test
- * @bug 8039080
- * @modules jdk.jcmd/sun.tools.jinfo
- * @run testng JInfoLauncherTest
- * @summary Test JInfo launcher argument parsing
- */
-@Test
-public class JInfoLauncherTest {
- public static final String VALIDATION_EXCEPTION_CLSNAME =
- IllegalArgumentException.class.getName();
-
- private Constructor<JInfo> jInfoConstructor;
- private Field fldUseSA;
-
- @BeforeClass
- public void setup() throws Exception {
- jInfoConstructor = JInfo.class.getDeclaredConstructor(String[].class);
- jInfoConstructor.setAccessible(true);
- fldUseSA = JInfo.class.getDeclaredField("useSA");
- fldUseSA.setAccessible(true);
- }
-
- private JInfo newJInfo(String[] args) throws Exception {
- try {
- return jInfoConstructor.newInstance((Object) args);
- } catch (Exception e) {
- if (isValidationException(e.getCause())) {
- throw (Exception)e.getCause();
- }
- throw e;
- }
- }
-
- private boolean getUseSA(JInfo jinfo) throws Exception {
- return fldUseSA.getBoolean(jinfo);
- }
-
- private void cmdPID(String cmd, String ... params) throws Exception {
- int offset = (cmd != null ? 1 : 0);
- String[] args = new String[offset + params.length];
- args[0] = cmd;
- System.arraycopy(params, 0, args, offset, params.length);
- JInfo j = newJInfo(args);
- assertFalse(getUseSA(j), "Local jinfo must not forward to SA");
- }
-
- private void cmdCore(String cmd, String ... params) throws Exception {
- int offset = (cmd != null ? 1 : 0);
- String[] args = new String[offset + params.length];
- args[0] = cmd;
- System.arraycopy(params, 0, args, offset, params.length);
- JInfo j = newJInfo(args);
- assertTrue(getUseSA(j), "Core jinfo must forward to SA");
- }
-
- private void cmdRemote(String cmd, String ... params) throws Exception {
- int offset = (cmd != null ? 1 : 0);
- String[] args = new String[offset + params.length];
- args[0] = cmd;
- System.arraycopy(params, 0, args, offset, params.length);
- JInfo j = newJInfo(args);
- assertTrue(getUseSA(j), "Remote jinfo must forward to SA");
- }
-
- private void cmdExtraArgs(String cmd, int argsLen) throws Exception {
- String[] args = new String[argsLen + 1 + (cmd != null ? 1 : 0)];
- Arrays.fill(args, "a");
- if (cmd != null) {
- args[0] = cmd;
- } else {
- cmd = "default";
- }
- try {
- JInfo j = newJInfo(args);
- fail("\"" + cmd + "\" does not support more than " + argsLen +
- " arguments");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- private void cmdMissingArgs(String cmd, int reqArgs) throws Exception {
- String[] args = new String[reqArgs - 1 + (cmd != null ? 1 : 0)];
- Arrays.fill(args, "a");
- if (cmd != null) {
- args[0] = cmd;
- } else {
- cmd = "default";
- }
- try {
- JInfo j = newJInfo(args);
- fail("\"" + cmd + "\" requires at least " + reqArgs + " argument");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testDefaultPID() throws Exception {
- cmdPID(null, "1234");
- }
-
- public void testFlagsPID() throws Exception {
- cmdPID("-flags", "1234");
- }
-
- public void testSyspropsPID() throws Exception {
- cmdPID("-sysprops", "1234");
- }
-
- public void testReadFlagPID() throws Exception {
- cmdPID("-flag", "SomeManagementFlag", "1234");
- }
-
- public void testSetFlag1PID() throws Exception {
- cmdPID("-flag", "+SomeManagementFlag", "1234");
- }
-
- public void testSetFlag2PID() throws Exception {
- cmdPID("-flag", "-SomeManagementFlag", "1234");
- }
-
- public void testSetFlag3PID() throws Exception {
- cmdPID("-flag", "SomeManagementFlag=314", "1234");
- }
-
- public void testDefaultCore() throws Exception {
- cmdCore(null, "myapp.exe", "my.core");
- }
-
- public void testFlagsCore() throws Exception {
- cmdCore("-flags", "myapp.exe", "my.core");
- }
-
- public void testSyspropsCore() throws Exception {
- cmdCore("-sysprops", "myapp.exe", "my.core");
- }
-
- public void testReadFlagCore() throws Exception {
- try {
- cmdCore("-flag", "SomeManagementFlag", "myapp.exe", "my.core");
- fail("Flags can not be read from core files");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testSetFlag1Core() throws Exception {
- try {
- cmdCore("-flag", "+SomeManagementFlag", "myapp.exe", "my.core");
- fail("Flags can not be set in core files");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testSetFlag2Core() throws Exception {
- try {
- cmdCore("-flag", "-SomeManagementFlag", "myapp.exe", "my.core");
- fail("Flags can not be set in core files");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testSetFlag3Core() throws Exception {
- try {
- cmdCore("-flag", "SomeManagementFlag=314", "myapp.exe", "my.core");
- fail("Flags can not be set in core files");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testDefaultRemote() throws Exception {
- cmdRemote(null, "serverid@host");
- }
-
- public void testFlagsRemote() throws Exception {
- cmdRemote("-flags", "serverid@host");
- }
-
- public void testSyspropsRemote() throws Exception {
- cmdRemote("-sysprops", "serverid@host");
- }
-
- public void testReadFlagRemote() throws Exception {
- try {
- cmdCore("-flag", "SomeManagementFlag", "serverid@host");
- fail("Flags can not be read from SA server");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testSetFlag1Remote() throws Exception {
- try {
- cmdCore("-flag", "+SomeManagementFlag","serverid@host");
- fail("Flags can not be set on SA server");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testSetFlag2Remote() throws Exception {
- try {
- cmdCore("-flag", "-SomeManagementFlag", "serverid@host");
- fail("Flags can not be read set on SA server");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testSetFlag3Remote() throws Exception {
- try {
- cmdCore("-flag", "SomeManagementFlag=314", "serverid@host");
- fail("Flags can not be read set on SA server");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- public void testDefaultExtraArgs() throws Exception {
- cmdExtraArgs(null, 2);
- }
-
- public void testFlagsExtraArgs() throws Exception {
- cmdExtraArgs("-flags", 2);
- }
-
- public void testSyspropsExtraArgs() throws Exception {
- cmdExtraArgs("-sysprops", 2);
- }
-
- public void testFlagExtraArgs() throws Exception {
- cmdExtraArgs("-flag", 2);
- }
-
- public void testHelp1ExtraArgs() throws Exception {
- cmdExtraArgs("-h", 0);
- }
-
- public void testHelp2ExtraArgs() throws Exception {
- cmdExtraArgs("-help", 0);
- }
-
- public void testDefaultMissingArgs() throws Exception {
- cmdMissingArgs(null, 1);
- }
-
- public void testFlagsMissingArgs() throws Exception {
- cmdMissingArgs("-flags", 1);
- }
-
- public void testSyspropsMissingArgs() throws Exception {
- cmdMissingArgs("-sysprops", 1);
- }
-
- public void testFlagMissingArgs() throws Exception {
- cmdMissingArgs("-flag", 2);
- }
-
- public void testUnknownCommand() throws Exception {
- try {
- JInfo j = newJInfo(new String[]{"-unknown_command"});
- fail("JInfo accepts unknown commands");
- } catch (Exception e) {
- if (!isValidationException(e)) {
- throw e;
- }
- // ignore
- }
- }
-
- private static boolean isValidationException(Throwable e) {
- return e.getClass().getName().equals(VALIDATION_EXCEPTION_CLSNAME);
- }
-}
--- a/jdk/test/sun/tools/jinfo/JInfoRunningProcessFlagTest.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * 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.
- */
-
-import java.lang.management.ManagementFactory;
-import com.sun.management.HotSpotDiagnosticMXBean;
-import jdk.testlibrary.OutputAnalyzer;
-import static jdk.testlibrary.Platform.isSolaris;
-import static jdk.testlibrary.Asserts.assertEquals;
-import static jdk.testlibrary.Asserts.assertNotEquals;
-import static jdk.testlibrary.Asserts.assertTrue;
-
-/**
- * @test
- * @summary The test sanity checks 'jinfo -flag' option.
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.* JInfoHelper
- * @run main/othervm -XX:+HeapDumpOnOutOfMemoryError JInfoRunningProcessFlagTest
- */
-public class JInfoRunningProcessFlagTest {
-
- public static void main(String[] args) throws Exception {
- testFlag();
- testFlagPlus();
- testFlagMinus();
- testFlagEqual();
-
- testInvalidFlag();
-
- testSolarisSpecificFlag();
- }
-
- private static void testFlag() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
- output.shouldHaveExitValue(0);
- assertTrue(output.getStderr().isEmpty(), "'jinfo -flag HeapDumpOnOutOfMemoryError' stderr should be empty");
- output.shouldContain("+HeapDumpOnOutOfMemoryError");
- }
-
- private static void testFlagPlus() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+HeapDumpOnOutOfMemoryError");
- output.shouldHaveExitValue(0);
- output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
- output.shouldHaveExitValue(0);
- output.shouldContain("+HeapDumpOnOutOfMemoryError");
- verifyIsEnabled("HeapDumpOnOutOfMemoryError");
- }
-
- private static void testFlagMinus() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-flag", "-HeapDumpOnOutOfMemoryError");
- output.shouldHaveExitValue(0);
- output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
- output.shouldHaveExitValue(0);
- output.shouldContain("-HeapDumpOnOutOfMemoryError");
- verifyIsDisabled("HeapDumpOnOutOfMemoryError");
- }
-
- private static void testFlagEqual() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError=1");
- output.shouldHaveExitValue(0);
- output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
- output.shouldHaveExitValue(0);
- output.shouldContain("+HeapDumpOnOutOfMemoryError");
- verifyIsEnabled("HeapDumpOnOutOfMemoryError");
- }
-
- private static void testInvalidFlag() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-flag", "monkey");
- assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid flag");
- }
-
- private static void testSolarisSpecificFlag() throws Exception {
- if (!isSolaris())
- return;
-
- OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+ExtendedDTraceProbes");
- output.shouldHaveExitValue(0);
- output = JInfoHelper.jinfo();
- output.shouldContain("+ExtendedDTraceProbes");
- verifyIsEnabled("ExtendedDTraceProbes");
-
- output = JInfoHelper.jinfo("-flag", "-ExtendedDTraceProbes");
- output.shouldHaveExitValue(0);
- output = JInfoHelper.jinfo();
- output.shouldContain("-ExtendedDTraceProbes");
- verifyIsDisabled("ExtendedDTraceProbes");
-
- output = JInfoHelper.jinfo("-flag", "ExtendedDTraceProbes");
- output.shouldContain("-ExtendedDTraceProbes");
- output.shouldHaveExitValue(0);
- }
-
- private static void verifyIsEnabled(String flag) {
- HotSpotDiagnosticMXBean hotspotDiagnostic =
- ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
- String flagValue = hotspotDiagnostic.getVMOption(flag).getValue();
- assertEquals(flagValue, "true", "Expected '" + flag + "' flag be enabled");
- }
-
- private static void verifyIsDisabled(String flag) {
- HotSpotDiagnosticMXBean hotspotDiagnostic =
- ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
- String flagValue = hotspotDiagnostic.getVMOption(flag).getValue();
- assertEquals(flagValue, "false", "Expected '" + flag + "' flag be disabled");
- }
-
-}
--- a/jdk/test/sun/tools/jinfo/JInfoRunningProcessTest.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * 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.
- */
-
-import jdk.testlibrary.OutputAnalyzer;
-import static jdk.testlibrary.Asserts.assertTrue;
-
-/**
- * @test
- * @summary The test sanity checks functionality of 'jinfo', 'jinfo -sysprops' and 'jinfo -flags'
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.* JInfoHelper
- * @run main/othervm -XX:+HeapDumpOnOutOfMemoryError JInfoRunningProcessTest
- */
-public class JInfoRunningProcessTest {
-
- public static void main(String[] args) throws Exception {
- testNoOptions();
- testSysprops();
- testFlags();
- }
-
- private static void testNoOptions() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo();
- output.shouldHaveExitValue(0);
- assertTrue(output.getStderr().isEmpty(), "'jinfo' stderr should be empty");
- output.shouldContain("+HeapDumpOnOutOfMemoryError");
- }
-
- private static void testSysprops() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-sysprops");
- output.shouldHaveExitValue(0);
- assertTrue(output.getStderr().isEmpty(), "'jinfo -sysprops' stderr should be empty");
- }
-
- private static void testFlags() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfo("-flags");
- output.shouldHaveExitValue(0);
- assertTrue(output.getStderr().isEmpty(), "'jinfo -flags' stderr should be empty");
- output.shouldContain("+HeapDumpOnOutOfMemoryError");
- }
-
-}
--- a/jdk/test/sun/tools/jinfo/JInfoSanityTest.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * 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.
- */
-
-import static jdk.testlibrary.Asserts.assertNotEquals;
-import static jdk.testlibrary.Asserts.assertTrue;
-import static jdk.testlibrary.Asserts.assertFalse;
-import jdk.testlibrary.OutputAnalyzer;
-
-/**
- * @test
- * @summary The test sanity checks functionality of 'jinfo -h', 'jinfo -help',
- * and verifies jinfo exits abnormally if started with invalid options.
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.* JInfoHelper
- * @run main JInfoSanityTest
- */
-public class JInfoSanityTest {
-
- public static void main(String[] args) throws Exception {
- test_h();
- test_help();
- testVersion();
- testUnknownHost();
- }
-
- private static void test_h() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfoNoPid("-h");
- output.shouldHaveExitValue(0);
- assertFalse(output.getStderr().isEmpty(), "'jinfo -h' stderr should not be empty");
- assertTrue(output.getStdout().isEmpty(), "'jinfo -h' stdout should be empty");
- }
-
- private static void test_help() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfoNoPid("-help");
- output.shouldHaveExitValue(0);
- assertFalse(output.getStderr().isEmpty(), "'jinfo -help' stderr should not be empty");
- assertTrue(output.getStdout().isEmpty(), "'jinfo -help' stdout should be empty");
- }
-
- private static void testVersion() throws Exception {
- OutputAnalyzer output = JInfoHelper.jinfoNoPid("-version");
- output.shouldHaveExitValue(1);
- assertFalse(output.getStderr().isEmpty(), "'jinfo -version' stderr should not be empty");
- assertTrue(output.getStdout().isEmpty(), "'jinfo -version' stdout should be empty");
- }
-
- private static void testUnknownHost() throws Exception {
- String unknownHost = "Oja781nh2ev7vcvbajdg-Sda1-C";
- OutputAnalyzer output = JInfoHelper.jinfoNoPid("med@" + unknownHost);
- assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid operation");
- output.shouldMatch(".*(Connection refused to host\\:|UnknownHostException\\:) " + unknownHost + ".*");
- }
-
-}
--- a/jdk/test/sun/tools/jmap/BasicJMapTest.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/sun/tools/jmap/BasicJMapTest.java Sat May 14 09:11:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -34,12 +34,10 @@
/*
* @test
- * @bug 6321286
* @summary Unit test for jmap utility
* @key intermittent
* @library /lib/testlibrary
* @library /test/lib/share/classes
- * @modules java.management
* @build jdk.testlibrary.*
* @build jdk.test.lib.hprof.*
* @build jdk.test.lib.hprof.model.*
@@ -54,6 +52,8 @@
public static void main(String[] args) throws Exception {
testHisto();
testHistoLive();
+ testFinalizerInfo();
+ testClstats();
testDump();
testDumpLive();
}
@@ -68,6 +68,16 @@
output.shouldHaveExitValue(0);
}
+ private static void testFinalizerInfo() throws Exception {
+ OutputAnalyzer output = jmap("-finalizerinfo");
+ output.shouldHaveExitValue(0);
+ }
+
+ private static void testClstats() throws Exception {
+ OutputAnalyzer output = jmap("-clstats");
+ output.shouldHaveExitValue(0);
+ }
+
private static void testDump() throws Exception {
dump(false);
}
@@ -105,7 +115,6 @@
private static OutputAnalyzer jmap(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap");
- launcher.addVMArg("-XX:+UsePerfData");
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);
--- a/jdk/test/sun/tools/jmap/heapconfig/JMapHeapConfigTest.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 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
- * 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.
- */
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import jdk.test.lib.apps.LingeredApp;
-import jdk.testlibrary.Utils;
-import jdk.testlibrary.Platform;
-
-/*
- * @test
- * @bug 8042397
- * @summary Unit test for jmap utility test heap configuration reader
- * @library /test/lib/share/classes
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.*
- * @build jdk.test.lib.apps.*
- * @build JMapHeapConfigTest TmtoolTestScenario
- * @run main JMapHeapConfigTest
- */
-public class JMapHeapConfigTest {
-
- static final String expectedJMapValues[] = {
- "MinHeapFreeRatio",
- "MaxHeapFreeRatio",
- "MaxHeapSize",
- "NewSize",
- "MaxNewSize",
- "OldSize",
- "NewRatio",
- "SurvivorRatio",
- "MetaspaceSize",
- "CompressedClassSpaceSize",
- "G1HeapRegionSize"};
-
- // ignoring MaxMetaspaceSize
-
- static final String desiredMaxHeapSize = "-Xmx128m";
-
- private static Map<String, String> parseJMapOutput(List<String> jmapOutput) {
- Map<String, String> heapConfigMap = new HashMap<String, String>();
- boolean shouldParse = false;
-
- for (String line : jmapOutput) {
- line = line.trim();
-
- if (line.startsWith("Heap Configuration:")) {
- shouldParse = true;
- continue;
- }
-
- if (line.startsWith("Heap Usage:")) {
- shouldParse = false;
- continue;
- }
-
- if (shouldParse && !line.equals("")) {
- String[] lv = line.split("\\s+");
- try {
- heapConfigMap.put(lv[0], lv[2]);
- } catch (ArrayIndexOutOfBoundsException ex) {
- // Ignore mailformed lines
- }
- }
- }
- return heapConfigMap;
- }
-
- // Compare stored values
- private static void compareValues(Map<String, String> parsedJMapOutput, Map<String, String> parsedVmOutput) {
- for (String key : expectedJMapValues) {
- try {
- String jmapVal = parsedJMapOutput.get(key);
- if (jmapVal == null) {
- throw new RuntimeException("Key '" + key + "' doesn't exists in jmap output");
- }
-
- String vmVal = parsedVmOutput.get(key);
- if (vmVal == null) {
- throw new RuntimeException("Key '" + key + "' doesn't exists in vm output");
- }
-
- if (new BigDecimal(jmapVal).compareTo(new BigDecimal(vmVal)) != 0) {
- throw new RuntimeException(String.format("Key %s doesn't match %s vs %s", key, vmVal, jmapVal));
- }
- } catch (NumberFormatException ex) {
- throw new RuntimeException("Unexpected key '" + key + "' value", ex);
- }
- }
- }
-
- public static void main(String[] args) throws Exception {
- System.out.println("Starting JMapHeapConfigTest");
-
- if (!Platform.shouldSAAttach()) {
- // Silently skip the test if we don't have enough permissions to attach
- System.err.println("Error! Insufficient permissions to attach.");
- return;
- }
-
- if (!LingeredApp.isLastModifiedWorking()) {
- // Exact behaviour of the test depends to operating system and the test nature,
- // so just print the warning and continue
- System.err.println("Warning! Last modified time doesn't work.");
- }
-
- boolean mx_found = false;
- List<String> jvmOptions = Utils.getVmOptions();
- for (String option : jvmOptions) {
- if (option.startsWith("-Xmx")) {
- System.out.println("INFO: maximum heap size set by JTREG as " + option);
- mx_found = true;
- break;
- }
- }
-
- // Forward vm options to LingeredApp
- ArrayList<String> cmd = new ArrayList();
- cmd.addAll(Utils.getVmOptions());
- if (!mx_found) {
- cmd.add(desiredMaxHeapSize);
- System.out.println("INFO: maximum heap size set explicitly as " + desiredMaxHeapSize);
- }
- cmd.add("-XX:+PrintFlagsFinal");
-
- TmtoolTestScenario tmt = TmtoolTestScenario.create("jmap", "-heap");
- int exitcode = tmt.launch(cmd);
- if (exitcode != 0) {
- throw new RuntimeException("Test FAILED jmap exits with non zero exit code " + exitcode);
- }
-
- Map<String,String> parsedJmapOutput = parseJMapOutput(tmt.getToolOutput());
- Map<String,String> parsedVMOutput = tmt.parseFlagsFinal();
-
- compareValues(parsedJmapOutput, parsedVMOutput);
-
- // If test fails it throws RuntimeException
- System.out.println("Test PASSED");
- }
-}
--- a/jdk/test/sun/tools/jmap/heapconfig/TmtoolTestScenario.java Sat May 14 03:45:59 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 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
- * 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.
- */
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import jdk.test.lib.apps.LingeredApp;
-import jdk.testlibrary.JDKToolLauncher;
-import jdk.testlibrary.Utils;
-
-public class TmtoolTestScenario {
-
- private final ArrayList<String> toolOutput = new ArrayList<String>();
- private LingeredApp theApp = null;
- private final String toolName;
- private final String[] toolArgs;
-
- /**
- * @param toolName - name of tool to test
- * @param toolArgs - tool arguments
- * @return the object
- */
- public static TmtoolTestScenario create(String toolName, String... toolArgs) {
- return new TmtoolTestScenario(toolName, toolArgs);
- }
-
- /**
- * @return STDOUT of tool
- */
- public List<String> getToolOutput() {
- return toolOutput;
- }
-
- /**
- *
- * @return STDOUT of test app
- */
- public List<String> getAppOutput() {
- return theApp.getAppOutput();
- }
-
- /**
- * @return Value of the app output with -XX:+PrintFlagsFinal as a map.
- */
- public Map<String, String> parseFlagsFinal() {
- List<String> astr = theApp.getAppOutput();
- Map<String, String> vmMap = new HashMap<String, String>();
-
- for (String line : astr) {
- String[] lv = line.trim().split("\\s+");
- try {
- vmMap.put(lv[1], lv[3]);
- } catch (ArrayIndexOutOfBoundsException ex) {
- // ignore mailformed lines
- }
- }
- return vmMap;
- }
-
- /**
- *
- * @param vmArgs - vm and java arguments to launch test app
- * @return exit code of tool
- */
- public int launch(List<String> vmArgs) {
- System.out.println("Starting LingeredApp");
- try {
- try {
- List<String> vmArgsExtended = new ArrayList<String>();
- vmArgsExtended.add("-XX:+UsePerfData");
- vmArgsExtended.addAll(vmArgs);
- theApp = LingeredApp.startApp(vmArgsExtended);
-
- System.out.println("Starting " + toolName + " against " + theApp.getPid());
- JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK(toolName);
-
- for (String cmd : toolArgs) {
- launcher.addToolArg(cmd);
- }
- launcher.addToolArg(Long.toString(theApp.getPid()));
-
- ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
- processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
- Process toolProcess = processBuilder.start();
-
- // By default child process output stream redirected to pipe, so we are reading it in foreground.
- BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
-
- String line;
- while ((line = reader.readLine()) != null) {
- toolOutput.add(line.trim());
- }
-
- toolProcess.waitFor();
-
- return toolProcess.exitValue();
- } finally {
- LingeredApp.stopApp(theApp);
- }
- } catch (IOException | InterruptedException ex) {
- throw new RuntimeException("Test ERROR " + ex, ex);
- }
- }
-
- public void launch(String... appArgs) throws IOException {
- launch(Arrays.asList(appArgs));
- }
-
- private TmtoolTestScenario(String toolName, String[] toolArgs) {
- this.toolName = toolName;
- this.toolArgs = toolArgs;
- }
-
-}
--- a/jdk/test/sun/tools/jstack/BasicJStackTest.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/sun/tools/jstack/BasicJStackTest.java Sat May 14 09:11:07 2016 -0700
@@ -29,10 +29,8 @@
/*
* @test
- * @bug 6260070
* @summary Unit test for jstack utility
* @library /lib/testlibrary
- * @modules java.management
* @build jdk.testlibrary.*
* @run main BasicJStackTest
*/
--- a/jdk/test/sun/tools/jstack/DeadlockDetectionTest.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/sun/tools/jstack/DeadlockDetectionTest.java Sat May 14 09:11:07 2016 -0700
@@ -39,7 +39,6 @@
* @summary Test deadlock detection
* @library /test/lib/share/classes
* @library /lib/testlibrary
- * @modules java.management
* @build jdk.testlibrary.*
* @build jdk.test.lib.apps.*
* @build DeadlockDetectionTest
--- a/jdk/test/sun/util/logging/PlatformLoggerTest.java Sat May 14 03:45:59 2016 +0000
+++ b/jdk/test/sun/util/logging/PlatformLoggerTest.java Sat May 14 09:11:07 2016 -0700
@@ -31,7 +31,6 @@
*
* @modules java.base/sun.util.logging
* java.logging/sun.util.logging.internal
- * @compile -XDignore.symbol.file PlatformLoggerTest.java
* @run main/othervm PlatformLoggerTest
*/
@@ -42,25 +41,31 @@
import static sun.util.logging.PlatformLogger.Level.*;
public class PlatformLoggerTest {
+
+ static Logger logger;
+ static PlatformLogger bar;
+ static PlatformLogger goo;
+ static PlatformLogger foo;
+
public static void main(String[] args) throws Exception {
final String FOO_PLATFORM_LOGGER = "test.platformlogger.foo";
final String BAR_PLATFORM_LOGGER = "test.platformlogger.bar";
final String GOO_PLATFORM_LOGGER = "test.platformlogger.goo";
final String BAR_LOGGER = "test.logger.bar";
- PlatformLogger goo = PlatformLogger.getLogger(GOO_PLATFORM_LOGGER);
+ goo = PlatformLogger.getLogger(GOO_PLATFORM_LOGGER);
// test the PlatformLogger methods
testLogMethods(goo);
// Create a platform logger using the default
- PlatformLogger foo = PlatformLogger.getLogger(FOO_PLATFORM_LOGGER);
+ foo = PlatformLogger.getLogger(FOO_PLATFORM_LOGGER);
checkPlatformLogger(foo, FOO_PLATFORM_LOGGER);
// create a java.util.logging.Logger
// now java.util.logging.Logger should be created for each platform logger
- Logger logger = Logger.getLogger(BAR_LOGGER);
+ logger = Logger.getLogger(BAR_LOGGER);
logger.setLevel(Level.WARNING);
- PlatformLogger bar = PlatformLogger.getLogger(BAR_PLATFORM_LOGGER);
+ bar = PlatformLogger.getLogger(BAR_PLATFORM_LOGGER);
checkPlatformLogger(bar, BAR_PLATFORM_LOGGER);
// test the PlatformLogger methods