/* * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @library /test/lib * @summary Test the handling of fields of unloaded value classes. * @compile -XDallowWithFieldOperator hack/GetUnresolvedValueFieldWrongSignature.java * @compile -XDallowWithFieldOperator TestUnloadedValueTypeField.java * @run main/othervm -XX:+EnableValhalla -Xcomp -XX:+Inline * -XX:CompileCommand=compileonly,TestUnloadedValueTypeField::test1 * -XX:CompileCommand=print,TestUnloadedValueTypeField::test1 * -XX:CompileCommand=compileonly,TestUnloadedValueTypeField::test2 * -XX:CompileCommand=compileonly,GetUnresolvedValueFieldWrongSignature::test3 * -XX:CompileCommand=compileonly,TestUnloadedValueTypeField::test4 * -XX:CompileCommand=compileonly,TestUnloadedValueTypeField::test5 * -XX:CompileCommand=compileonly,TestUnloadedValueTypeField::test11 * -XX:CompileCommand=compileonly,TestUnloadedValueTypeField::test12 * TestUnloadedValueTypeField */ import jdk.test.lib.Asserts; public class TestUnloadedValueTypeField { static final int WARMUP_LOOPS = 10000; static public void main(String[] args) { // instance fields test1_verifier(); test2_verifier(); test3_verifier(); test4_verifier(); test5_verifier(); // static fields test11_verifier(); test12_verifier(); } // Test case 1: // The value type field class has been loaded, but the holder class has not been loaded. // // aload_0 // getfield MyValue1Holder.v:QMyValue1; // ^ not loaded ^ already loaded // // MyValue1 has already been loaded, because it's in the ValueType attribute of // TestUnloadedValueTypeField, due to TestUnloadedValueTypeField.test1_precondition(). static value final class MyValue1 { final int foo = 0; static MyValue1 make() { return __WithField(MyValue1.default.foo, 1234); } } static class MyValue1Holder { MyValue1 v; public MyValue1Holder() { v = MyValue1.make(); } } static MyValue1 test1_precondition() { return MyValue1.make(); } static int test1(MyValue1Holder holder) { if (holder != null) { return holder.v.foo + 1; } else { return 0; } } static void test1_verifier() { for (int i=0; i