diff --git a/.hgtags b/.hgtags index 8fc0c97d3e13a0100c41845d980e342db9382552..7c1fe11703d8a092eff80f855449d7974b216f75 100644 --- a/.hgtags +++ b/.hgtags @@ -495,3 +495,4 @@ b15553cde967dfd7781a4a5c669e4cb7db734317 jdk8u20-b19 4828415ebbf11e205dcc08e97ad5ae7dd03522f9 jdk8u20-b21 e4a6e7f1b90b85270aee1c54edaca3ef737082f1 hs25.20-b21 f7429096a202cab5c36a0f20dea33c554026010f jdk8u20-b22 +7c56530b11496459e66cb9ea933035002311672c hs25.20-b22 diff --git a/make/hotspot_version b/make/hotspot_version index c5fe26d62edbf6277f053d741048fb9b10427488..14df69697d5d10b62dc2f1742a9ef8274905dfb5 100644 --- a/make/hotspot_version +++ b/make/hotspot_version @@ -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 diff --git a/src/share/vm/c1/c1_GraphBuilder.cpp b/src/share/vm/c1/c1_GraphBuilder.cpp index 3c39a13a92c896bdb8ef8405575add270c436a62..6d9daf5a4b3f79873d18fe0a414c8da7cf9d7c03 100644 --- a/src/share/vm/c1/c1_GraphBuilder.cpp +++ b/src/share/vm/c1/c1_GraphBuilder.cpp @@ -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 diff --git a/src/share/vm/opto/callGenerator.cpp b/src/share/vm/opto/callGenerator.cpp index aaeb70388201824608fad081f00dde8c725b7aba..42ed3bc605a213f35cc99f3c6f4bf14b33499bdf 100644 --- a/src/share/vm/opto/callGenerator.cpp +++ b/src/share/vm/opto/callGenerator.cpp @@ -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 diff --git a/src/share/vm/opto/compile.hpp b/src/share/vm/opto/compile.hpp index 57b0e8b80c61d5476356002a8095f7bc4a32acfe..acfae5245641dbe6d2d7a6af3ca6cc68cc6535ce 100644 --- a/src/share/vm/opto/compile.hpp +++ b/src/share/vm/opto/compile.hpp @@ -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); diff --git a/src/share/vm/opto/doCall.cpp b/src/share/vm/opto/doCall.cpp index cd077753b09980fda14aa75360a5a1848ddbf8c2..7e8ff1c3977ee21af1b2aa24604d7faa55eb2a47 100644 --- a/src/share/vm/opto/doCall.cpp +++ b/src/share/vm/opto/doCall.cpp @@ -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; } diff --git a/test/compiler/stable/StableConfiguration.java b/test/compiler/stable/StableConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..09e395707e7dc6f5bc0963ab7c88447227890a49 --- /dev/null +++ b/test/compiler/stable/StableConfiguration.java @@ -0,0 +1,62 @@ +/* + * 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); + } + } + +} diff --git a/test/compiler/stable/TestStableBoolean.java b/test/compiler/stable/TestStableBoolean.java index 37f42875022571964f0d4c85d81f9a4cfd79d5f3..37641d1b101d77a8d9ab270bf831334317cacf35 100644 --- a/test/compiler/stable/TestStableBoolean.java +++ b/test/compiler/stable/TestStableBoolean.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableByte.java b/test/compiler/stable/TestStableByte.java index 4a14fcc3b2fadf355a4376cf96cf665354d99e9b..c62bc35081fe7e30ff34017e215084dc652ffb73 100644 --- a/test/compiler/stable/TestStableByte.java +++ b/test/compiler/stable/TestStableByte.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableChar.java b/test/compiler/stable/TestStableChar.java index ede8e9a4df7318aecc7e8805b13eff42c6d3e5c7..55bf749bf02f32011a23c31d81066a6efee95922 100644 --- a/test/compiler/stable/TestStableChar.java +++ b/test/compiler/stable/TestStableChar.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableDouble.java b/test/compiler/stable/TestStableDouble.java index b656acbd1aec3f211ae643b34e6c6ae8f0db20db..112d83633b69565dcdd2e8511a41c5719c816cee 100644 --- a/test/compiler/stable/TestStableDouble.java +++ b/test/compiler/stable/TestStableDouble.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableFloat.java b/test/compiler/stable/TestStableFloat.java index ab1c3f0be1f8efed17ea24f635c15cc736cf359c..973a6016575c77ab76aff2918d6fa7f7911a831e 100644 --- a/test/compiler/stable/TestStableFloat.java +++ b/test/compiler/stable/TestStableFloat.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableInt.java b/test/compiler/stable/TestStableInt.java index 9632a8dc39d4cb16e87ccd78d4707ea9d2daf418..bf7fe337baa8302865ebb94722edc242293fce4a 100644 --- a/test/compiler/stable/TestStableInt.java +++ b/test/compiler/stable/TestStableInt.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableLong.java b/test/compiler/stable/TestStableLong.java index d1c72f5609c7f7c02c41fd9aecdfa8d25594f1de..f97e7e143d00b0cf60e55a501ee2538425aa0550 100644 --- a/test/compiler/stable/TestStableLong.java +++ b/test/compiler/stable/TestStableLong.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableObject.java b/test/compiler/stable/TestStableObject.java index 7958c6500c44f240c6dcfa72995ac2fe10b1f0ac..dec466adc03262f87753c1161f5a900d77e482f3 100644 --- a/test/compiler/stable/TestStableObject.java +++ b/test/compiler/stable/TestStableObject.java @@ -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())); - } } diff --git a/test/compiler/stable/TestStableShort.java b/test/compiler/stable/TestStableShort.java index a80d0726db6cfc9f5ce86a3a3dbf35b2e5c82c23..67a7f0453fb26fcbaccbf5ad6d0e517a1c337a59 100644 --- a/test/compiler/stable/TestStableShort.java +++ b/test/compiler/stable/TestStableShort.java @@ -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())); - } }