提交 2b9ed6f3 编写于 作者: A asaha

Merge

......@@ -495,3 +495,4 @@ b15553cde967dfd7781a4a5c669e4cb7db734317 jdk8u20-b19
4828415ebbf11e205dcc08e97ad5ae7dd03522f9 jdk8u20-b21
e4a6e7f1b90b85270aee1c54edaca3ef737082f1 hs25.20-b21
f7429096a202cab5c36a0f20dea33c554026010f jdk8u20-b22
7c56530b11496459e66cb9ea933035002311672c hs25.20-b22
......@@ -35,7 +35,7 @@ HOTSPOT_VM_COPYRIGHT=Copyright 2014
HS_MAJOR_VER=25
HS_MINOR_VER=20
HS_BUILD_NUMBER=21
HS_BUILD_NUMBER=22
JDK_MAJOR_VER=1
JDK_MINOR_VER=8
......
......@@ -1569,6 +1569,7 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
default:
constant = new Constant(as_ValueType(field_val));
}
// Stable static fields are checked for non-default values in ciField::initialize_from().
}
if (constant != NULL) {
push(type, append(constant));
......@@ -1610,6 +1611,10 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
default:
constant = new Constant(as_ValueType(field_val));
}
if (FoldStableValues && field->is_stable() && field_val.is_null_or_zero()) {
// Stable field with default value can't be constant.
constant = NULL;
}
} else {
// For CallSite objects treat the target field as a compile time constant.
if (const_oop->is_call_site()) {
......@@ -1993,7 +1998,13 @@ void GraphBuilder::invoke(Bytecodes::Code code) {
if (!UseInlineCaches && is_loaded && code == Bytecodes::_invokevirtual
&& !target->can_be_statically_bound()) {
// Find a vtable index if one is available
vtable_index = target->resolve_vtable_index(calling_klass, callee_holder);
// For arrays, callee_holder is Object. Resolving the call with
// Object would allow an illegal call to finalize() on an
// array. We use holder instead: illegal calls to finalize() won't
// be compiled as vtable calls (IC call resolution will catch the
// illegal call) and the few legal calls on array types won't be
// either.
vtable_index = target->resolve_vtable_index(calling_klass, holder);
}
#endif
......
......@@ -837,8 +837,11 @@ CallGenerator* CallGenerator::for_method_handle_inline(JVMState* jvms, ciMethod*
Node* receiver_node = kit.argument(0);
const TypeOopPtr* receiver_type = gvn.type(receiver_node)->isa_oopptr();
// call_does_dispatch and vtable_index are out-parameters. They might be changed.
target = C->optimize_virtual_call(caller, jvms->bci(), klass, target, receiver_type,
is_virtual,
// optimize_virtual_call() takes 2 different holder
// arguments for a corner case that doesn't apply here (see
// Parse::do_call())
target = C->optimize_virtual_call(caller, jvms->bci(), klass, klass,
target, receiver_type, is_virtual,
call_does_dispatch, vtable_index); // out-parameters
// We lack profiling at this call but type speculation may
// provide us with a type
......
......@@ -854,8 +854,8 @@ class Compile : public Phase {
// Helper functions to identify inlining potential at call-site
ciMethod* optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
ciMethod* callee, const TypeOopPtr* receiver_type,
bool is_virtual,
ciKlass* holder, ciMethod* callee,
const TypeOopPtr* receiver_type, bool is_virtual,
bool &call_does_dispatch, int &vtable_index);
ciMethod* optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass* klass,
ciMethod* callee, const TypeOopPtr* receiver_type);
......
......@@ -460,8 +460,14 @@ void Parse::do_call() {
Node* receiver_node = stack(sp() - nargs);
const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
// call_does_dispatch and vtable_index are out-parameters. They might be changed.
callee = C->optimize_virtual_call(method(), bci(), klass, orig_callee, receiver_type,
is_virtual,
// For arrays, klass below is Object. When vtable calls are used,
// resolving the call with Object would allow an illegal call to
// finalize() on an array. We use holder instead: illegal calls to
// finalize() won't be compiled as vtable calls (IC call
// resolution will catch the illegal call) and the few legal calls
// on array types won't be either.
callee = C->optimize_virtual_call(method(), bci(), klass, holder, orig_callee,
receiver_type, is_virtual,
call_does_dispatch, vtable_index); // out-parameters
speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
}
......@@ -937,8 +943,8 @@ void Parse::count_compiled_calls(bool at_method_entry, bool is_inline) {
ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
ciMethod* callee, const TypeOopPtr* receiver_type,
bool is_virtual,
ciKlass* holder, ciMethod* callee,
const TypeOopPtr* receiver_type, bool is_virtual,
bool& call_does_dispatch, int& vtable_index) {
// Set default values for out-parameters.
call_does_dispatch = true;
......@@ -953,7 +959,7 @@ ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKl
call_does_dispatch = false;
} else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
// We can make a vtable call at this site
vtable_index = callee->resolve_vtable_index(caller->holder(), klass);
vtable_index = callee->resolve_vtable_index(caller->holder(), holder);
}
return callee;
}
......@@ -976,8 +982,10 @@ ciMethod* Compile::optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass*
ciInstanceKlass* actual_receiver = klass;
if (receiver_type != NULL) {
// Array methods are all inherited from Object, and are monomorphic.
// finalize() call on array is not allowed.
if (receiver_type->isa_aryptr() &&
callee->holder() == env()->Object_klass()) {
callee->holder() == env()->Object_klass() &&
callee->name() != ciSymbol::finalize_method_name()) {
return callee;
}
......
/*
* 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.
*/
package java.lang.invoke;
import java.lang.reflect.Method;
import java.util.Properties;
import sun.hotspot.WhiteBox;
public class StableConfiguration {
static final WhiteBox WB = WhiteBox.getWhiteBox();
static final boolean isStableEnabled;
static final boolean isServerWithStable;
static {
Boolean value = WB.getBooleanVMFlag("FoldStableValues");
isStableEnabled = (value == null ? false : value);
isServerWithStable = isStableEnabled && get();
System.out.println("@Stable: " + (isStableEnabled ? "enabled" : "disabled"));
System.out.println("Server Compiler: " + get());
}
// ::get() is among immediately compiled methods.
static boolean get() {
try {
Method m = StableConfiguration.class.getDeclaredMethod("get");
int level = WB.getMethodCompilationLevel(m);
if (level > 0) {
return (level == 4);
} else {
String javaVM = System.getProperty("java.vm.name", "");
if (javaVM.contains("Server")) return true;
if (javaVM.contains("Client")) return false;
throw new Error("Unknown VM type: "+javaVM);
}
} catch (NoSuchMethodException e) {
throw new Error(e);
}
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableBoolean
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableBoolean.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableBoolean StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableBoolean
* java/lang/invoke/TestStableBoolean$BooleanStable
* java/lang/invoke/TestStableBoolean$StaticBooleanStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableBoolean$NestedStableField3
* java/lang/invoke/TestStableBoolean$NestedStableField3$A
* java/lang/invoke/TestStableBoolean$DefaultValue
* java/lang/invoke/TestStableBoolean$DefaultStaticValue
* java/lang/invoke/TestStableBoolean$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableBoolean
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableBoolean
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableBoolean
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableBoolean
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableBoolean
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableBoolean
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableBoolean {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(BooleanStable.class);
run(DefaultStaticValue.class);
run(StaticBooleanStable.class);
run(VolatileBooleanStable.class);
......@@ -145,6 +161,21 @@ public class TestStableBoolean {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable boolean v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static boolean get() { return c.v; }
public static void test() throws Exception {
boolean val1 = get();
c.v = true; boolean val2 = get();
assertEquals(val1, false);
assertEquals(val2, true);
}
}
/* ==================================================== */
static class StaticBooleanStable {
public static @Stable boolean v;
......@@ -188,14 +219,14 @@ public class TestStableBoolean {
c.v = new boolean[1]; c.v[0] = true; boolean val1 = get();
c.v[0] = false; boolean val2 = get();
assertEquals(val1, true);
assertEquals(val2, (isStableEnabled ? true : false));
assertEquals(val2, (isServerWithStable ? true : false));
}
{
c.v = new boolean[20]; c.v[10] = true; boolean val1 = get1();
c.v[10] = false; boolean val2 = get1();
assertEquals(val1, true);
assertEquals(val2, (isStableEnabled ? true : false));
assertEquals(val2, (isServerWithStable ? true : false));
}
{
......@@ -220,19 +251,19 @@ public class TestStableBoolean {
c.v = new boolean[1][1]; c.v[0][0] = true; boolean val1 = get();
c.v[0][0] = false; boolean val2 = get();
assertEquals(val1, true);
assertEquals(val2, (isStableEnabled ? true : false));
assertEquals(val2, (isServerWithStable ? true : false));
c.v = new boolean[1][1]; c.v[0][0] = false; boolean val3 = get();
assertEquals(val3, (isStableEnabled ? true : false));
assertEquals(val3, (isServerWithStable ? true : false));
c.v[0] = new boolean[1]; c.v[0][0] = false; boolean val4 = get();
assertEquals(val4, (isStableEnabled ? true : false));
assertEquals(val4, (isServerWithStable ? true : false));
}
{
c.v = new boolean[1][1]; boolean[] val1 = get1();
c.v[0] = new boolean[1]; boolean[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -258,28 +289,28 @@ public class TestStableBoolean {
c.v = new boolean[1][1][1]; c.v[0][0][0] = true; boolean val1 = get();
c.v[0][0][0] = false; boolean val2 = get();
assertEquals(val1, true);
assertEquals(val2, (isStableEnabled ? true : false));
assertEquals(val2, (isServerWithStable ? true : false));
c.v = new boolean[1][1][1]; c.v[0][0][0] = false; boolean val3 = get();
assertEquals(val3, (isStableEnabled ? true : false));
assertEquals(val3, (isServerWithStable ? true : false));
c.v[0] = new boolean[1][1]; c.v[0][0][0] = false; boolean val4 = get();
assertEquals(val4, (isStableEnabled ? true : false));
assertEquals(val4, (isServerWithStable ? true : false));
c.v[0][0] = new boolean[1]; c.v[0][0][0] = false; boolean val5 = get();
assertEquals(val5, (isStableEnabled ? true : false));
assertEquals(val5, (isServerWithStable ? true : false));
}
{
c.v = new boolean[1][1][1]; boolean[] val1 = get1();
c.v[0][0] = new boolean[1]; boolean[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new boolean[1][1][1]; boolean[][] val1 = get2();
c.v[0] = new boolean[1][1]; boolean[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -306,37 +337,37 @@ public class TestStableBoolean {
c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = true; boolean val1 = get();
c.v[0][0][0][0] = false; boolean val2 = get();
assertEquals(val1, true);
assertEquals(val2, (isStableEnabled ? true : false));
assertEquals(val2, (isServerWithStable ? true : false));
c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = false; boolean val3 = get();
assertEquals(val3, (isStableEnabled ? true : false));
assertEquals(val3, (isServerWithStable ? true : false));
c.v[0] = new boolean[1][1][1]; c.v[0][0][0][0] = false; boolean val4 = get();
assertEquals(val4, (isStableEnabled ? true : false));
assertEquals(val4, (isServerWithStable ? true : false));
c.v[0][0] = new boolean[1][1]; c.v[0][0][0][0] = false; boolean val5 = get();
assertEquals(val5, (isStableEnabled ? true : false));
assertEquals(val5, (isServerWithStable ? true : false));
c.v[0][0][0] = new boolean[1]; c.v[0][0][0][0] = false; boolean val6 = get();
assertEquals(val6, (isStableEnabled ? true : false));
assertEquals(val6, (isServerWithStable ? true : false));
}
{
c.v = new boolean[1][1][1][1]; boolean[] val1 = get1();
c.v[0][0][0] = new boolean[1]; boolean[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new boolean[1][1][1][1]; boolean[][] val1 = get2();
c.v[0][0] = new boolean[1][1]; boolean[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new boolean[1][1][1][1]; boolean[][][] val1 = get3();
c.v[0] = new boolean[1][1][1]; boolean[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -399,7 +430,7 @@ public class TestStableBoolean {
c.v = new boolean[1][1]; c.v[0] = new boolean[0]; boolean[] val1 = get1();
c.v[0] = new boolean[0]; boolean[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -435,14 +466,14 @@ public class TestStableBoolean {
c.v = new boolean[1][1][1]; c.v[0][0] = new boolean[0]; boolean[] val1 = get1();
c.v[0][0] = new boolean[0]; boolean[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new boolean[1][1][1]; c.v[0] = new boolean[0][0]; boolean[][] val1 = get2();
c.v[0] = new boolean[0][0]; boolean[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -577,7 +608,7 @@ public class TestStableBoolean {
elem.a = false; boolean val3 = get(); boolean val4 = get1();
assertEquals(val1, true);
assertEquals(val3, (isStableEnabled ? true : false));
assertEquals(val3, (isServerWithStable ? true : false));
assertEquals(val2, true);
assertEquals(val4, false);
......@@ -611,17 +642,4 @@ public class TestStableBoolean {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableByte
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableByte.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableByte StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableByte
* java/lang/invoke/TestStableByte$ByteStable
* java/lang/invoke/TestStableByte$StaticByteStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableByte$NestedStableField3
* java/lang/invoke/TestStableByte$NestedStableField3$A
* java/lang/invoke/TestStableByte$DefaultValue
* java/lang/invoke/TestStableByte$DefaultStaticValue
* java/lang/invoke/TestStableByte$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableByte
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableByte
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableByte
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableByte
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableByte
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableByte
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableByte {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(ByteStable.class);
run(DefaultStaticValue.class);
run(StaticByteStable.class);
run(VolatileByteStable.class);
......@@ -145,6 +161,21 @@ public class TestStableByte {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable byte v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static byte get() { return c.v; }
public static void test() throws Exception {
byte val1 = get();
c.v = 1; byte val2 = get();
assertEquals(val1, 0);
assertEquals(val2, 1);
}
}
/* ==================================================== */
static class StaticByteStable {
public static @Stable byte v;
......@@ -188,20 +219,22 @@ public class TestStableByte {
c.v = new byte[1]; c.v[0] = 1; byte val1 = get();
c.v[0] = 2; byte val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new byte[1]; c.v[0] = 3; byte val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
c.v = new byte[20]; c.v[10] = 1; byte val1 = get1();
c.v[10] = 2; byte val2 = get1();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new byte[20]; c.v[10] = 3; byte val3 = get1();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
......@@ -226,19 +259,21 @@ public class TestStableByte {
c.v = new byte[1][1]; c.v[0][0] = 1; byte val1 = get();
c.v[0][0] = 2; byte val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new byte[1][1]; c.v[0][0] = 3; byte val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new byte[1]; c.v[0][0] = 4; byte val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
}
{
c.v = new byte[1][1]; byte[] val1 = get1();
c.v[0] = new byte[1]; byte[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableByte {
c.v = new byte[1][1][1]; c.v[0][0][0] = 1; byte val1 = get();
c.v[0][0][0] = 2; byte val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new byte[1][1][1]; c.v[0][0][0] = 3; byte val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new byte[1][1]; c.v[0][0][0] = 4; byte val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new byte[1]; c.v[0][0][0] = 5; byte val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
}
{
c.v = new byte[1][1][1]; byte[] val1 = get1();
c.v[0][0] = new byte[1]; byte[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new byte[1][1][1]; byte[][] val1 = get2();
c.v[0] = new byte[1][1]; byte[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableByte {
c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 1; byte val1 = get();
c.v[0][0][0][0] = 2; byte val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 3; byte val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new byte[1][1][1]; c.v[0][0][0][0] = 4; byte val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new byte[1][1]; c.v[0][0][0][0] = 5; byte val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
c.v[0][0][0] = new byte[1]; c.v[0][0][0][0] = 6; byte val6 = get();
assertEquals(val6, (isStableEnabled ? 1 : 6));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 6));
}
{
c.v = new byte[1][1][1][1]; byte[] val1 = get1();
c.v[0][0][0] = new byte[1]; byte[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new byte[1][1][1][1]; byte[][] val1 = get2();
c.v[0][0] = new byte[1][1]; byte[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new byte[1][1][1][1]; byte[][][] val1 = get3();
c.v[0] = new byte[1][1][1]; byte[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -404,7 +446,7 @@ public class TestStableByte {
c.v = new byte[1][1]; c.v[0] = new byte[0]; byte[] val1 = get1();
c.v[0] = new byte[0]; byte[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -440,14 +482,14 @@ public class TestStableByte {
c.v = new byte[1][1][1]; c.v[0][0] = new byte[0]; byte[] val1 = get1();
c.v[0][0] = new byte[0]; byte[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new byte[1][1][1]; c.v[0] = new byte[0][0]; byte[][] val1 = get2();
c.v[0] = new byte[0][0]; byte[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -582,7 +624,7 @@ public class TestStableByte {
elem.a = 2; byte val3 = get(); byte val4 = get1();
assertEquals(val1, 1);
assertEquals(val3, (isStableEnabled ? 1 : 2));
assertEquals(val3, (isServerWithStable ? 1 : 2));
assertEquals(val2, 1);
assertEquals(val4, 2);
......@@ -616,17 +658,4 @@ public class TestStableByte {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableChar
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableChar.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableChar StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableChar
* java/lang/invoke/TestStableChar$CharStable
* java/lang/invoke/TestStableChar$StaticCharStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableChar$NestedStableField3
* java/lang/invoke/TestStableChar$NestedStableField3$A
* java/lang/invoke/TestStableChar$DefaultValue
* java/lang/invoke/TestStableChar$DefaultStaticValue
* java/lang/invoke/TestStableChar$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableChar
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableChar
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableChar
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableChar
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableChar
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableChar
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableChar {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(CharStable.class);
run(DefaultStaticValue.class);
run(StaticCharStable.class);
run(VolatileCharStable.class);
......@@ -145,6 +161,21 @@ public class TestStableChar {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable char v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static char get() { return c.v; }
public static void test() throws Exception {
char val1 = get();
c.v = 'a'; char val2 = get();
assertEquals(val1, 0);
assertEquals(val2, 'a');
}
}
/* ==================================================== */
static class StaticCharStable {
public @Stable char v;
......@@ -188,20 +219,22 @@ public class TestStableChar {
c.v = new char[1]; c.v[0] = 'a'; char val1 = get();
c.v[0] = 'b'; char val2 = get();
assertEquals(val1, 'a');
assertEquals(val2, (isStableEnabled ? 'a' : 'b'));
assertEquals(val2, (isServerWithStable ? 'a' : 'b'));
c.v = new char[1]; c.v[0] = 'c'; char val3 = get();
assertEquals(val3, (isStableEnabled ? 'a' : 'c'));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'c'));
}
{
c.v = new char[20]; c.v[10] = 'a'; char val1 = get1();
c.v[10] = 'b'; char val2 = get1();
assertEquals(val1, 'a');
assertEquals(val2, (isStableEnabled ? 'a' : 'b'));
assertEquals(val2, (isServerWithStable ? 'a' : 'b'));
c.v = new char[20]; c.v[10] = 'c'; char val3 = get1();
assertEquals(val3, (isStableEnabled ? 'a' : 'c'));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'c'));
}
{
......@@ -226,19 +259,21 @@ public class TestStableChar {
c.v = new char[1][1]; c.v[0][0] = 'a'; char val1 = get();
c.v[0][0] = 'b'; char val2 = get();
assertEquals(val1, 'a');
assertEquals(val2, (isStableEnabled ? 'a' : 'b'));
assertEquals(val2, (isServerWithStable ? 'a' : 'b'));
c.v = new char[1][1]; c.v[0][0] = 'c'; char val3 = get();
assertEquals(val3, (isStableEnabled ? 'a' : 'c'));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'c'));
c.v[0] = new char[1]; c.v[0][0] = 'd'; char val4 = get();
assertEquals(val4, (isStableEnabled ? 'a' : 'd'));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'd'));
}
{
c.v = new char[1][1]; char[] val1 = get1();
c.v[0] = new char[1]; char[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableChar {
c.v = new char[1][1][1]; c.v[0][0][0] = 'a'; char val1 = get();
c.v[0][0][0] = 'b'; char val2 = get();
assertEquals(val1, 'a');
assertEquals(val2, (isStableEnabled ? 'a' : 'b'));
assertEquals(val2, (isServerWithStable ? 'a' : 'b'));
c.v = new char[1][1][1]; c.v[0][0][0] = 'c'; char val3 = get();
assertEquals(val3, (isStableEnabled ? 'a' : 'c'));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'c'));
c.v[0] = new char[1][1]; c.v[0][0][0] = 'd'; char val4 = get();
assertEquals(val4, (isStableEnabled ? 'a' : 'd'));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'd'));
c.v[0][0] = new char[1]; c.v[0][0][0] = 'e'; char val5 = get();
assertEquals(val5, (isStableEnabled ? 'a' : 'e'));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'e'));
}
{
c.v = new char[1][1][1]; char[] val1 = get1();
c.v[0][0] = new char[1]; char[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new char[1][1][1]; char[][] val1 = get2();
c.v[0] = new char[1][1]; char[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableChar {
c.v = new char[1][1][1][1]; c.v[0][0][0][0] = 'a'; char val1 = get();
c.v[0][0][0][0] = 'b'; char val2 = get();
assertEquals(val1, 'a');
assertEquals(val2, (isStableEnabled ? 'a' : 'b'));
assertEquals(val2, (isServerWithStable ? 'a' : 'b'));
c.v = new char[1][1][1][1]; c.v[0][0][0][0] = 'c'; char val3 = get();
assertEquals(val3, (isStableEnabled ? 'a' : 'c'));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'c'));
c.v[0] = new char[1][1][1]; c.v[0][0][0][0] = 'd'; char val4 = get();
assertEquals(val4, (isStableEnabled ? 'a' : 'd'));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'd'));
c.v[0][0] = new char[1][1]; c.v[0][0][0][0] = 'e'; char val5 = get();
assertEquals(val5, (isStableEnabled ? 'a' : 'e'));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'e'));
c.v[0][0][0] = new char[1]; c.v[0][0][0][0] = 'f'; char val6 = get();
assertEquals(val6, (isStableEnabled ? 'a' : 'f'));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 'a' : 'b')
: 'f'));
}
{
c.v = new char[1][1][1][1]; char[] val1 = get1();
c.v[0][0][0] = new char[1]; char[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new char[1][1][1][1]; char[][] val1 = get2();
c.v[0][0] = new char[1][1]; char[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new char[1][1][1][1]; char[][][] val1 = get3();
c.v[0] = new char[1][1][1]; char[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -350,7 +392,6 @@ public class TestStableChar {
c.v = new char[1][1][1][1]; char[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
......@@ -403,7 +444,7 @@ public class TestStableChar {
c.v = new char[1][1]; c.v[0] = new char[0]; char[] val1 = get1();
c.v[0] = new char[0]; char[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -439,14 +480,14 @@ public class TestStableChar {
c.v = new char[1][1][1]; c.v[0][0] = new char[0]; char[] val1 = get1();
c.v[0][0] = new char[0]; char[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new char[1][1][1]; c.v[0] = new char[0][0]; char[][] val1 = get2();
c.v[0] = new char[0][0]; char[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -581,7 +622,7 @@ public class TestStableChar {
elem.a = 'b'; char val3 = get(); char val4 = get1();
assertEquals(val1, 'a');
assertEquals(val3, (isStableEnabled ? 'a' : 'b'));
assertEquals(val3, (isServerWithStable ? 'a' : 'b'));
assertEquals(val2, 'a');
assertEquals(val4, 'b');
......@@ -615,17 +656,4 @@ public class TestStableChar {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableDouble
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableDouble.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableDouble StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableDouble
* java/lang/invoke/TestStableDouble$DoubleStable
* java/lang/invoke/TestStableDouble$StaticDoubleStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableDouble$NestedStableField3
* java/lang/invoke/TestStableDouble$NestedStableField3$A
* java/lang/invoke/TestStableDouble$DefaultValue
* java/lang/invoke/TestStableDouble$DefaultStaticValue
* java/lang/invoke/TestStableDouble$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableDouble
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableDouble
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableDouble
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableDouble
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableDouble
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableDouble
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableDouble {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(DoubleStable.class);
run(DefaultStaticValue.class);
run(StaticDoubleStable.class);
run(VolatileDoubleStable.class);
......@@ -145,6 +161,21 @@ public class TestStableDouble {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable double v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static double get() { return c.v; }
public static void test() throws Exception {
double val1 = get();
c.v = 1.0; double val2 = get();
assertEquals(val1, 0);
assertEquals(val2, 1.0);
}
}
/* ==================================================== */
static class StaticDoubleStable {
public static @Stable double v;
......@@ -188,20 +219,22 @@ public class TestStableDouble {
c.v = new double[1]; c.v[0] = 1.0; double val1 = get();
c.v[0] = 2.0; double val2 = get();
assertEquals(val1, 1.0);
assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
c.v = new double[1]; c.v[0] = 3.0; double val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 3.0));
}
{
c.v = new double[20]; c.v[10] = 1.0; double val1 = get1();
c.v[10] = 2.0; double val2 = get1();
assertEquals(val1, 1.0);
assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
c.v = new double[20]; c.v[10] = 3.0; double val3 = get1();
assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 3.0));
}
{
......@@ -226,19 +259,21 @@ public class TestStableDouble {
c.v = new double[1][1]; c.v[0][0] = 1.0; double val1 = get();
c.v[0][0] = 2.0; double val2 = get();
assertEquals(val1, 1.0);
assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
c.v = new double[1][1]; c.v[0][0] = 3.0; double val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 3.0));
c.v[0] = new double[1]; c.v[0][0] = 4.0; double val4 = get();
assertEquals(val4, (isStableEnabled ? 1.0 : 4.0));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 4.0));
}
{
c.v = new double[1][1]; double[] val1 = get1();
c.v[0] = new double[1]; double[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableDouble {
c.v = new double[1][1][1]; c.v[0][0][0] = 1.0; double val1 = get();
c.v[0][0][0] = 2.0; double val2 = get();
assertEquals(val1, 1.0);
assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
c.v = new double[1][1][1]; c.v[0][0][0] = 3.0; double val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 3.0));
c.v[0] = new double[1][1]; c.v[0][0][0] = 4.0; double val4 = get();
assertEquals(val4, (isStableEnabled ? 1.0 : 4.0));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 4.0));
c.v[0][0] = new double[1]; c.v[0][0][0] = 5.0; double val5 = get();
assertEquals(val5, (isStableEnabled ? 1.0 : 5.0));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 5.0));
}
{
c.v = new double[1][1][1]; double[] val1 = get1();
c.v[0][0] = new double[1]; double[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new double[1][1][1]; double[][] val1 = get2();
c.v[0] = new double[1][1]; double[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableDouble {
c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 1.0; double val1 = get();
c.v[0][0][0][0] = 2.0; double val2 = get();
assertEquals(val1, 1.0);
assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 3.0; double val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 3.0));
c.v[0] = new double[1][1][1]; c.v[0][0][0][0] = 4.0; double val4 = get();
assertEquals(val4, (isStableEnabled ? 1.0 : 4.0));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 4.0));
c.v[0][0] = new double[1][1]; c.v[0][0][0][0] = 5.0; double val5 = get();
assertEquals(val5, (isStableEnabled ? 1.0 : 5.0));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 5.0));
c.v[0][0][0] = new double[1]; c.v[0][0][0][0] = 6.0; double val6 = get();
assertEquals(val6, (isStableEnabled ? 1.0 : 6.0));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
: 6.0));
}
{
c.v = new double[1][1][1][1]; double[] val1 = get1();
c.v[0][0][0] = new double[1]; double[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new double[1][1][1][1]; double[][] val1 = get2();
c.v[0][0] = new double[1][1]; double[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new double[1][1][1][1]; double[][][] val1 = get3();
c.v[0] = new double[1][1][1]; double[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -350,13 +392,11 @@ public class TestStableDouble {
c.v = new double[1][1][1][1]; double[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
/* ==================================================== */
// Dynamic Dim is higher than static
static class ObjectArrayLowerDim0 {
public @Stable Object v;
......@@ -404,7 +444,7 @@ public class TestStableDouble {
c.v = new double[1][1]; c.v[0] = new double[0]; double[] val1 = get1();
c.v[0] = new double[0]; double[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -440,14 +480,14 @@ public class TestStableDouble {
c.v = new double[1][1][1]; c.v[0][0] = new double[0]; double[] val1 = get1();
c.v[0][0] = new double[0]; double[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new double[1][1][1]; c.v[0] = new double[0][0]; double[][] val1 = get2();
c.v[0] = new double[0][0]; double[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -582,7 +622,7 @@ public class TestStableDouble {
elem.a = 2.0; double val3 = get(); double val4 = get1();
assertEquals(val1, 1.0);
assertEquals(val3, (isStableEnabled ? 1.0 : 2.0));
assertEquals(val3, (isServerWithStable ? 1.0 : 2.0));
assertEquals(val2, 1.0);
assertEquals(val4, 2.0);
......@@ -616,17 +656,4 @@ public class TestStableDouble {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableFloat
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableFloat.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableFloat StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableFloat
* java/lang/invoke/TestStableFloat$FloatStable
* java/lang/invoke/TestStableFloat$StaticFloatStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableFloat$NestedStableField3
* java/lang/invoke/TestStableFloat$NestedStableField3$A
* java/lang/invoke/TestStableFloat$DefaultValue
* java/lang/invoke/TestStableFloat$DefaultStaticValue
* java/lang/invoke/TestStableFloat$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableFloat
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableFloat
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableFloat
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableFloat
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableFloat
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableFloat
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableFloat {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(FloatStable.class);
run(DefaultStaticValue.class);
run(StaticFloatStable.class);
run(VolatileFloatStable.class);
......@@ -145,6 +161,21 @@ public class TestStableFloat {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable float v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static float get() { return c.v; }
public static void test() throws Exception {
float val1 = get();
c.v = 1.0F; float val2 = get();
assertEquals(val1, 0F);
assertEquals(val2, 1.0F);
}
}
/* ==================================================== */
static class StaticFloatStable {
public static @Stable float v;
......@@ -188,20 +219,22 @@ public class TestStableFloat {
c.v = new float[1]; c.v[0] = 1.0F; float val1 = get();
c.v[0] = 2.0F; float val2 = get();
assertEquals(val1, 1.0F);
assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
c.v = new float[1]; c.v[0] = 3.0F; float val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0F : 3.0F));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 3.0F));
}
{
c.v = new float[20]; c.v[10] = 1.0F; float val1 = get1();
c.v[10] = 2.0F; float val2 = get1();
assertEquals(val1, 1.0F);
assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
c.v = new float[20]; c.v[10] = 3.0F; float val3 = get1();
assertEquals(val3, (isStableEnabled ? 1.0F : 3.0F));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 3.0F));
}
{
......@@ -226,19 +259,21 @@ public class TestStableFloat {
c.v = new float[1][1]; c.v[0][0] = 1.0F; float val1 = get();
c.v[0][0] = 2.0F; float val2 = get();
assertEquals(val1, 1.0F);
assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
c.v = new float[1][1]; c.v[0][0] = 3.0F; float val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0F : 3.0F));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 3.0F));
c.v[0] = new float[1]; c.v[0][0] = 4.0F; float val4 = get();
assertEquals(val4, (isStableEnabled ? 1.0F : 4.0F));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 4.0F));
}
{
c.v = new float[1][1]; float[] val1 = get1();
c.v[0] = new float[1]; float[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableFloat {
c.v = new float[1][1][1]; c.v[0][0][0] = 1.0F; float val1 = get();
c.v[0][0][0] = 2.0F; float val2 = get();
assertEquals(val1, 1.0F);
assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
c.v = new float[1][1][1]; c.v[0][0][0] = 3.0F; float val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0F : 3.0F));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 3.0F));
c.v[0] = new float[1][1]; c.v[0][0][0] = 4.0F; float val4 = get();
assertEquals(val4, (isStableEnabled ? 1.0F : 4.0F));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 4.0F));
c.v[0][0] = new float[1]; c.v[0][0][0] = 5.0F; float val5 = get();
assertEquals(val5, (isStableEnabled ? 1.0F : 5.0F));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 5.0F));
}
{
c.v = new float[1][1][1]; float[] val1 = get1();
c.v[0][0] = new float[1]; float[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new float[1][1][1]; float[][] val1 = get2();
c.v[0] = new float[1][1]; float[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableFloat {
c.v = new float[1][1][1][1]; c.v[0][0][0][0] = 1.0F; float val1 = get();
c.v[0][0][0][0] = 2.0F; float val2 = get();
assertEquals(val1, 1.0F);
assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
c.v = new float[1][1][1][1]; c.v[0][0][0][0] = 3.0F; float val3 = get();
assertEquals(val3, (isStableEnabled ? 1.0F : 3.0F));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 3.0F));
c.v[0] = new float[1][1][1]; c.v[0][0][0][0] = 4.0F; float val4 = get();
assertEquals(val4, (isStableEnabled ? 1.0F : 4.0F));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 4.0F));
c.v[0][0] = new float[1][1]; c.v[0][0][0][0] = 5.0F; float val5 = get();
assertEquals(val5, (isStableEnabled ? 1.0F : 5.0F));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 5.0F));
c.v[0][0][0] = new float[1]; c.v[0][0][0][0] = 6.0F; float val6 = get();
assertEquals(val6, (isStableEnabled ? 1.0F : 6.0F));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
: 6.0F));
}
{
c.v = new float[1][1][1][1]; float[] val1 = get1();
c.v[0][0][0] = new float[1]; float[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new float[1][1][1][1]; float[][] val1 = get2();
c.v[0][0] = new float[1][1]; float[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new float[1][1][1][1]; float[][][] val1 = get3();
c.v[0] = new float[1][1][1]; float[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -350,13 +392,11 @@ public class TestStableFloat {
c.v = new float[1][1][1][1]; float[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
/* ==================================================== */
// Dynamic Dim is higher than static
static class ObjectArrayLowerDim0 {
public @Stable Object v;
......@@ -404,7 +444,7 @@ public class TestStableFloat {
c.v = new float[1][1]; c.v[0] = new float[0]; float[] val1 = get1();
c.v[0] = new float[0]; float[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -440,14 +480,14 @@ public class TestStableFloat {
c.v = new float[1][1][1]; c.v[0][0] = new float[0]; float[] val1 = get1();
c.v[0][0] = new float[0]; float[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new float[1][1][1]; c.v[0] = new float[0][0]; float[][] val1 = get2();
c.v[0] = new float[0][0]; float[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -582,7 +622,7 @@ public class TestStableFloat {
elem.a = 2.0F; float val3 = get(); float val4 = get1();
assertEquals(val1, 1.0F);
assertEquals(val3, (isStableEnabled ? 1.0F : 2.0F));
assertEquals(val3, (isServerWithStable ? 1.0F : 2.0F));
assertEquals(val2, 1.0F);
assertEquals(val4, 2.0F);
......@@ -616,17 +656,4 @@ public class TestStableFloat {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableInt
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableInt.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableInt StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableInt
* java/lang/invoke/TestStableInt$IntStable
* java/lang/invoke/TestStableInt$StaticIntStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableInt$NestedStableField3
* java/lang/invoke/TestStableInt$NestedStableField3$A
* java/lang/invoke/TestStableInt$DefaultValue
* java/lang/invoke/TestStableInt$DefaultStaticValue
* java/lang/invoke/TestStableInt$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableInt
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableInt
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableInt
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableInt
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableInt
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableInt
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableInt {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(IntStable.class);
run(DefaultStaticValue.class);
run(StaticIntStable.class);
run(VolatileIntStable.class);
......@@ -145,6 +161,21 @@ public class TestStableInt {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable int v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static int get() { return c.v; }
public static void test() throws Exception {
int val1 = get();
c.v = 1; int val2 = get();
assertEquals(val1, 0);
assertEquals(val2, 1);
}
}
/* ==================================================== */
static class StaticIntStable {
public static @Stable int v;
......@@ -188,20 +219,22 @@ public class TestStableInt {
c.v = new int[1]; c.v[0] = 1; int val1 = get();
c.v[0] = 2; int val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new int[1]; c.v[0] = 3; int val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
c.v = new int[20]; c.v[10] = 1; int val1 = get1();
c.v[10] = 2; int val2 = get1();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new int[20]; c.v[10] = 3; int val3 = get1();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
......@@ -226,19 +259,21 @@ public class TestStableInt {
c.v = new int[1][1]; c.v[0][0] = 1; int val1 = get();
c.v[0][0] = 2; int val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new int[1][1]; c.v[0][0] = 3; int val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new int[1]; c.v[0][0] = 4; int val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
}
{
c.v = new int[1][1]; int[] val1 = get1();
c.v[0] = new int[1]; int[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableInt {
c.v = new int[1][1][1]; c.v[0][0][0] = 1; int val1 = get();
c.v[0][0][0] = 2; int val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new int[1][1][1]; c.v[0][0][0] = 3; int val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new int[1][1]; c.v[0][0][0] = 4; int val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new int[1]; c.v[0][0][0] = 5; int val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
}
{
c.v = new int[1][1][1]; int[] val1 = get1();
c.v[0][0] = new int[1]; int[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new int[1][1][1]; int[][] val1 = get2();
c.v[0] = new int[1][1]; int[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableInt {
c.v = new int[1][1][1][1]; c.v[0][0][0][0] = 1; int val1 = get();
c.v[0][0][0][0] = 2; int val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new int[1][1][1][1]; c.v[0][0][0][0] = 3; int val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new int[1][1][1]; c.v[0][0][0][0] = 4; int val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new int[1][1]; c.v[0][0][0][0] = 5; int val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
c.v[0][0][0] = new int[1]; c.v[0][0][0][0] = 6; int val6 = get();
assertEquals(val6, (isStableEnabled ? 1 : 6));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 6));
}
{
c.v = new int[1][1][1][1]; int[] val1 = get1();
c.v[0][0][0] = new int[1]; int[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new int[1][1][1][1]; int[][] val1 = get2();
c.v[0][0] = new int[1][1]; int[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new int[1][1][1][1]; int[][][] val1 = get3();
c.v[0] = new int[1][1][1]; int[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -350,13 +392,11 @@ public class TestStableInt {
c.v = new int[1][1][1][1]; int[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
/* ==================================================== */
// Dynamic Dim is higher than static
static class ObjectArrayLowerDim0 {
public @Stable Object v;
......@@ -404,7 +444,7 @@ public class TestStableInt {
c.v = new int[1][1]; c.v[0] = new int[0]; int[] val1 = get1();
c.v[0] = new int[0]; int[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -440,14 +480,14 @@ public class TestStableInt {
c.v = new int[1][1][1]; c.v[0][0] = new int[0]; int[] val1 = get1();
c.v[0][0] = new int[0]; int[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new int[1][1][1]; c.v[0] = new int[0][0]; int[][] val1 = get2();
c.v[0] = new int[0][0]; int[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -582,7 +622,7 @@ public class TestStableInt {
elem.a = 2; int val3 = get(); int val4 = get1();
assertEquals(val1, 1);
assertEquals(val3, (isStableEnabled ? 1 : 2));
assertEquals(val3, (isServerWithStable ? 1 : 2));
assertEquals(val2, 1);
assertEquals(val4, 2);
......@@ -616,17 +656,4 @@ public class TestStableInt {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableLong
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableLong.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableLong StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableLong
* java/lang/invoke/TestStableLong$LongStable
* java/lang/invoke/TestStableLong$StaticLongStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableLong$NestedStableField3
* java/lang/invoke/TestStableLong$NestedStableField3$A
* java/lang/invoke/TestStableLong$DefaultValue
* java/lang/invoke/TestStableLong$DefaultStaticValue
* java/lang/invoke/TestStableLong$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableLong
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableLong
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableLong
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableLong
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableLong
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableLong
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableLong {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(LongStable.class);
run(DefaultStaticValue.class);
run(StaticLongStable.class);
run(VolatileLongStable.class);
......@@ -145,6 +161,21 @@ public class TestStableLong {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable long v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static long get() { return c.v; }
public static void test() throws Exception {
long val1 = get();
c.v = 1L; long val2 = get();
assertEquals(val1, 0);
assertEquals(val2, 1L);
}
}
/* ==================================================== */
static class StaticLongStable {
public static @Stable long v;
......@@ -188,20 +219,22 @@ public class TestStableLong {
c.v = new long[1]; c.v[0] = 1; long val1 = get();
c.v[0] = 2; long val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new long[1]; c.v[0] = 3; long val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
c.v = new long[20]; c.v[10] = 1; long val1 = get1();
c.v[10] = 2; long val2 = get1();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new long[20]; c.v[10] = 3; long val3 = get1();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
......@@ -226,19 +259,21 @@ public class TestStableLong {
c.v = new long[1][1]; c.v[0][0] = 1; long val1 = get();
c.v[0][0] = 2; long val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new long[1][1]; c.v[0][0] = 3; long val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new long[1]; c.v[0][0] = 4; long val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
}
{
c.v = new long[1][1]; long[] val1 = get1();
c.v[0] = new long[1]; long[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableLong {
c.v = new long[1][1][1]; c.v[0][0][0] = 1; long val1 = get();
c.v[0][0][0] = 2; long val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new long[1][1][1]; c.v[0][0][0] = 3; long val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new long[1][1]; c.v[0][0][0] = 4; long val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new long[1]; c.v[0][0][0] = 5; long val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
}
{
c.v = new long[1][1][1]; long[] val1 = get1();
c.v[0][0] = new long[1]; long[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new long[1][1][1]; long[][] val1 = get2();
c.v[0] = new long[1][1]; long[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableLong {
c.v = new long[1][1][1][1]; c.v[0][0][0][0] = 1; long val1 = get();
c.v[0][0][0][0] = 2; long val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new long[1][1][1][1]; c.v[0][0][0][0] = 3; long val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new long[1][1][1]; c.v[0][0][0][0] = 4; long val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new long[1][1]; c.v[0][0][0][0] = 5; long val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
c.v[0][0][0] = new long[1]; c.v[0][0][0][0] = 6; long val6 = get();
assertEquals(val6, (isStableEnabled ? 1 : 6));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 6));
}
{
c.v = new long[1][1][1][1]; long[] val1 = get1();
c.v[0][0][0] = new long[1]; long[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new long[1][1][1][1]; long[][] val1 = get2();
c.v[0][0] = new long[1][1]; long[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new long[1][1][1][1]; long[][][] val1 = get3();
c.v[0] = new long[1][1][1]; long[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -350,13 +392,11 @@ public class TestStableLong {
c.v = new long[1][1][1][1]; long[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
/* ==================================================== */
// Dynamic Dim is higher than static
static class ObjectArrayLowerDim0 {
public @Stable Object v;
......@@ -404,7 +444,7 @@ public class TestStableLong {
c.v = new long[1][1]; c.v[0] = new long[0]; long[] val1 = get1();
c.v[0] = new long[0]; long[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -440,14 +480,14 @@ public class TestStableLong {
c.v = new long[1][1][1]; c.v[0][0] = new long[0]; long[] val1 = get1();
c.v[0][0] = new long[0]; long[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new long[1][1][1]; c.v[0] = new long[0][0]; long[][] val1 = get2();
c.v[0] = new long[0][0]; long[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -582,7 +622,7 @@ public class TestStableLong {
elem.a = 2; long val3 = get(); long val4 = get1();
assertEquals(val1, 1);
assertEquals(val3, (isStableEnabled ? 1 : 2));
assertEquals(val3, (isServerWithStable ? 1 : 2));
assertEquals(val2, 1);
assertEquals(val4, 2);
......@@ -616,17 +656,4 @@ public class TestStableLong {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableObject
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableObject.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableObject StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableObject
* java/lang/invoke/TestStableObject$ObjectStable
* java/lang/invoke/TestStableObject$StaticObjectStable
......@@ -49,46 +51,60 @@
* java/lang/invoke/TestStableObject$NestedStableField3$A
* java/lang/invoke/TestStableObject$Values
* java/lang/invoke/TestStableObject$DefaultValue
* java/lang/invoke/TestStableObject$DefaultStaticValue
* java/lang/invoke/TestStableObject$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableObject
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableObject
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableObject
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableObject
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableObject
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableObject
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableObject {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(ObjectStable.class);
run(DefaultStaticValue.class);
run(StaticObjectStable.class);
run(VolatileObjectStable.class);
......@@ -148,6 +164,21 @@ public class TestStableObject {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable Object v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static Object get() { return c.v; }
public static void test() throws Exception {
Object val1 = get();
c.v = Values.A; Object val2 = get();
assertEquals(val1, null);
assertEquals(val2, Values.A);
}
}
/* ==================================================== */
static class StaticObjectStable {
public static @Stable Values v;
......@@ -191,20 +222,22 @@ public class TestStableObject {
c.v = new Object[1]; c.v[0] = Values.A; Object val1 = get();
c.v[0] = Values.B; Object val2 = get();
assertEquals(val1, Values.A);
assertEquals(val2, (isStableEnabled ? Values.A : Values.B));
assertEquals(val2, (isServerWithStable ? Values.A : Values.B));
c.v = new Object[1]; c.v[0] = Values.C; Object val3 = get();
assertEquals(val3, (isStableEnabled ? Values.A : Values.C));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.C));
}
{
c.v = new Object[20]; c.v[10] = Values.A; Object val1 = get1();
c.v[10] = Values.B; Object val2 = get1();
assertEquals(val1, Values.A);
assertEquals(val2, (isStableEnabled ? Values.A : Values.B));
assertEquals(val2, (isServerWithStable ? Values.A : Values.B));
c.v = new Object[20]; c.v[10] = Values.C; Object val3 = get1();
assertEquals(val3, (isStableEnabled ? Values.A : Values.C));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.C));
}
{
......@@ -229,19 +262,21 @@ public class TestStableObject {
c.v = new Object[1][1]; c.v[0][0] = Values.A; Object val1 = get();
c.v[0][0] = Values.B; Object val2 = get();
assertEquals(val1, Values.A);
assertEquals(val2, (isStableEnabled ? Values.A : Values.B));
assertEquals(val2, (isServerWithStable ? Values.A : Values.B));
c.v = new Object[1][1]; c.v[0][0] = Values.C; Object val3 = get();
assertEquals(val3, (isStableEnabled ? Values.A : Values.C));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.C));
c.v[0] = new Object[1]; c.v[0][0] = Values.D; Object val4 = get();
assertEquals(val4, (isStableEnabled ? Values.A : Values.D));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.D));
}
{
c.v = new Object[1][1]; Object[] val1 = get1();
c.v[0] = new Object[1]; Object[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -267,28 +302,31 @@ public class TestStableObject {
c.v = new Object[1][1][1]; c.v[0][0][0] = Values.A; Object val1 = get();
c.v[0][0][0] = Values.B; Object val2 = get();
assertEquals(val1, Values.A);
assertEquals(val2, (isStableEnabled ? Values.A : Values.B));
assertEquals(val2, (isServerWithStable ? Values.A : Values.B));
c.v = new Object[1][1][1]; c.v[0][0][0] = Values.C; Object val3 = get();
assertEquals(val3, (isStableEnabled ? Values.A : Values.C));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.C));
c.v[0] = new Object[1][1]; c.v[0][0][0] = Values.D; Object val4 = get();
assertEquals(val4, (isStableEnabled ? Values.A : Values.D));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.D));
c.v[0][0] = new Object[1]; c.v[0][0][0] = Values.E; Object val5 = get();
assertEquals(val5, (isStableEnabled ? Values.A : Values.E));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.E));
}
{
c.v = new Object[1][1][1]; Object[] val1 = get1();
c.v[0][0] = new Object[1]; Object[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new Object[1][1][1]; Object[][] val1 = get2();
c.v[0] = new Object[1][1]; Object[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -315,37 +353,41 @@ public class TestStableObject {
c.v = new Object[1][1][1][1]; c.v[0][0][0][0] = Values.A; Object val1 = get();
c.v[0][0][0][0] = Values.B; Object val2 = get();
assertEquals(val1, Values.A);
assertEquals(val2, (isStableEnabled ? Values.A : Values.B));
assertEquals(val2, (isServerWithStable ? Values.A : Values.B));
c.v = new Object[1][1][1][1]; c.v[0][0][0][0] = Values.C; Object val3 = get();
assertEquals(val3, (isStableEnabled ? Values.A : Values.C));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.C));
c.v[0] = new Object[1][1][1]; c.v[0][0][0][0] = Values.D; Object val4 = get();
assertEquals(val4, (isStableEnabled ? Values.A : Values.D));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.D));
c.v[0][0] = new Object[1][1]; c.v[0][0][0][0] = Values.E; Object val5 = get();
assertEquals(val5, (isStableEnabled ? Values.A : Values.E));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.E));
c.v[0][0][0] = new Object[1]; c.v[0][0][0][0] = Values.F; Object val6 = get();
assertEquals(val6, (isStableEnabled ? Values.A : Values.F));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? Values.A : Values.B)
: Values.F));
}
{
c.v = new Object[1][1][1][1]; Object[] val1 = get1();
c.v[0][0][0] = new Object[1]; Object[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new Object[1][1][1][1]; Object[][] val1 = get2();
c.v[0][0] = new Object[1][1]; Object[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new Object[1][1][1][1]; Object[][][] val1 = get3();
c.v[0] = new Object[1][1][1]; Object[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -353,13 +395,11 @@ public class TestStableObject {
c.v = new Object[1][1][1][1]; Object[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
/* ==================================================== */
// Dynamic Dim is higher than static
static class ObjectArrayLowerDim0 {
public @Stable Object v;
......@@ -407,7 +447,7 @@ public class TestStableObject {
c.v = new Object[1][1]; c.v[0] = new Object[0]; Object[] val1 = get1();
c.v[0] = new Object[0]; Object[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -443,14 +483,14 @@ public class TestStableObject {
c.v = new Object[1][1][1]; c.v[0][0] = new Object[0]; Object[] val1 = get1();
c.v[0][0] = new Object[0]; Object[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new Object[1][1][1]; c.v[0] = new Object[0][0]; Object[][] val1 = get2();
c.v[0] = new Object[0][0]; Object[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -585,7 +625,7 @@ public class TestStableObject {
elem.a = Values.B; Object val3 = get(); Object val4 = get1();
assertEquals(val1, Values.A);
assertEquals(val3, (isStableEnabled ? Values.A : Values.B));
assertEquals(val3, (isServerWithStable ? Values.A : Values.B));
assertEquals(val2, Values.A);
assertEquals(val4, Values.B);
......@@ -619,17 +659,4 @@ public class TestStableObject {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
......@@ -26,9 +26,11 @@
/*
* @test TestStableShort
* @summary tests on stable fields and arrays
* @library /testlibrary
* @compile -XDignore.symbol.file TestStableShort.java
* @library /testlibrary /testlibrary/whitebox
* @build TestStableShort StableConfiguration sun.hotspot.WhiteBox
* @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main ClassFileInstaller
* java/lang/invoke/StableConfiguration
* java/lang/invoke/TestStableShort
* java/lang/invoke/TestStableShort$ShortStable
* java/lang/invoke/TestStableShort$StaticShortStable
......@@ -48,46 +50,60 @@
* java/lang/invoke/TestStableShort$NestedStableField3
* java/lang/invoke/TestStableShort$NestedStableField3$A
* java/lang/invoke/TestStableShort$DefaultValue
* java/lang/invoke/TestStableShort$DefaultStaticValue
* java/lang/invoke/TestStableShort$ObjectArrayLowerDim2
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableShort
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableShort
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableShort
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableShort
*
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
* -server -XX:-TieredCompilation -Xcomp
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:+FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableShort
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
* -client -XX:-TieredCompilation
* -XX:-FoldStableValues
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
* java.lang.invoke.TestStableShort
*/
package java.lang.invoke;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import sun.management.ManagementFactoryHelper;
import java.lang.reflect.InvocationTargetException;
public class TestStableShort {
public static void main(String[] args) throws Exception {
System.out.println("@Stable enabled: "+isStableEnabled);
System.out.println();
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
public static void main(String[] args) throws Exception {
run(DefaultValue.class);
run(ShortStable.class);
run(DefaultStaticValue.class);
run(StaticShortStable.class);
run(VolatileShortStable.class);
......@@ -145,6 +161,21 @@ public class TestStableShort {
/* ==================================================== */
static class DefaultStaticValue {
public static @Stable short v;
public static final DefaultStaticValue c = new DefaultStaticValue();
public static short get() { return c.v; }
public static void test() throws Exception {
short val1 = get();
c.v = 1; short val2 = get();
assertEquals(val1, 0);
assertEquals(val2, 1);
}
}
/* ==================================================== */
static class StaticShortStable {
public static @Stable short v;
......@@ -188,20 +219,22 @@ public class TestStableShort {
c.v = new short[1]; c.v[0] = 1; short val1 = get();
c.v[0] = 2; short val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new short[1]; c.v[0] = 3; short val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
c.v = new short[20]; c.v[10] = 1; short val1 = get1();
c.v[10] = 2; short val2 = get1();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new short[20]; c.v[10] = 3; short val3 = get1();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
}
{
......@@ -226,19 +259,21 @@ public class TestStableShort {
c.v = new short[1][1]; c.v[0][0] = 1; short val1 = get();
c.v[0][0] = 2; short val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new short[1][1]; c.v[0][0] = 3; short val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new short[1]; c.v[0][0] = 4; short val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
}
{
c.v = new short[1][1]; short[] val1 = get1();
c.v[0] = new short[1]; short[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -264,28 +299,31 @@ public class TestStableShort {
c.v = new short[1][1][1]; c.v[0][0][0] = 1; short val1 = get();
c.v[0][0][0] = 2; short val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new short[1][1][1]; c.v[0][0][0] = 3; short val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new short[1][1]; c.v[0][0][0] = 4; short val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new short[1]; c.v[0][0][0] = 5; short val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
}
{
c.v = new short[1][1][1]; short[] val1 = get1();
c.v[0][0] = new short[1]; short[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new short[1][1][1]; short[][] val1 = get2();
c.v[0] = new short[1][1]; short[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -312,37 +350,41 @@ public class TestStableShort {
c.v = new short[1][1][1][1]; c.v[0][0][0][0] = 1; short val1 = get();
c.v[0][0][0][0] = 2; short val2 = get();
assertEquals(val1, 1);
assertEquals(val2, (isStableEnabled ? 1 : 2));
assertEquals(val2, (isServerWithStable ? 1 : 2));
c.v = new short[1][1][1][1]; c.v[0][0][0][0] = 3; short val3 = get();
assertEquals(val3, (isStableEnabled ? 1 : 3));
assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 3));
c.v[0] = new short[1][1][1]; c.v[0][0][0][0] = 4; short val4 = get();
assertEquals(val4, (isStableEnabled ? 1 : 4));
assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 4));
c.v[0][0] = new short[1][1]; c.v[0][0][0][0] = 5; short val5 = get();
assertEquals(val5, (isStableEnabled ? 1 : 5));
assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 5));
c.v[0][0][0] = new short[1]; c.v[0][0][0][0] = 6; short val6 = get();
assertEquals(val6, (isStableEnabled ? 1 : 6));
assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
: 6));
}
{
c.v = new short[1][1][1][1]; short[] val1 = get1();
c.v[0][0][0] = new short[1]; short[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new short[1][1][1][1]; short[][] val1 = get2();
c.v[0][0] = new short[1][1]; short[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new short[1][1][1][1]; short[][][] val1 = get3();
c.v[0] = new short[1][1][1]; short[][][] val2 = get3();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -350,13 +392,11 @@ public class TestStableShort {
c.v = new short[1][1][1][1]; short[][][][] val2 = get4();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
}
}
}
/* ==================================================== */
// Dynamic Dim is higher than static
static class ObjectArrayLowerDim0 {
public @Stable Object v;
......@@ -404,7 +444,7 @@ public class TestStableShort {
c.v = new short[1][1]; c.v[0] = new short[0]; short[] val1 = get1();
c.v[0] = new short[0]; short[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -440,14 +480,14 @@ public class TestStableShort {
c.v = new short[1][1][1]; c.v[0][0] = new short[0]; short[] val1 = get1();
c.v[0][0] = new short[0]; short[] val2 = get1();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
c.v = new short[1][1][1]; c.v[0] = new short[0][0]; short[][] val1 = get2();
c.v[0] = new short[0][0]; short[][] val2 = get2();
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
}
{
......@@ -582,7 +622,7 @@ public class TestStableShort {
elem.a = 2; short val3 = get(); short val4 = get1();
assertEquals(val1, 1);
assertEquals(val3, (isStableEnabled ? 1 : 2));
assertEquals(val3, (isServerWithStable ? 1 : 2));
assertEquals(val2, 1);
assertEquals(val4, 2);
......@@ -616,17 +656,4 @@ public class TestStableShort {
}
}
}
static final boolean isStableEnabled;
static {
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption("FoldStableValues");
} catch (IllegalArgumentException e) {
tmp = null;
}
isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册