1 /* 2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.lang.constant.DirectMethodHandleDesc; 25 import jdk.incubator.code.CodeReflection; 26 27 import static java.lang.constant.DirectMethodHandleDesc.Kind; 28 import static java.lang.constant.DirectMethodHandleDesc.Kind.VIRTUAL; 29 30 /* 31 * @test 32 * @summary Smoke test for code reflection with enum access. 33 * @modules jdk.incubator.code 34 * @build EnumAccessTest 35 * @build CodeReflectionTester 36 * @run main CodeReflectionTester EnumAccessTest 37 */ 38 39 public class EnumAccessTest { 40 @CodeReflection 41 @IR(""" 42 func @"test1" (%0 : EnumAccessTest)java.lang.constant.DirectMethodHandleDesc$Kind -> { 43 %1 : java.lang.constant.DirectMethodHandleDesc$Kind = field.load @"java.lang.constant.DirectMethodHandleDesc$Kind::VIRTUAL()java.lang.constant.DirectMethodHandleDesc$Kind"; 44 return %1; 45 }; 46 """) 47 DirectMethodHandleDesc.Kind test1() { 48 return DirectMethodHandleDesc.Kind.VIRTUAL; 49 } 50 51 @CodeReflection 52 @IR(""" 53 func @"test2" (%0 : EnumAccessTest)java.lang.constant.DirectMethodHandleDesc$Kind -> { 54 %1 : java.lang.constant.DirectMethodHandleDesc$Kind = field.load @"java.lang.constant.DirectMethodHandleDesc$Kind::VIRTUAL()java.lang.constant.DirectMethodHandleDesc$Kind"; 55 return %1; 56 }; 57 """) 58 DirectMethodHandleDesc.Kind test2() { 59 return Kind.VIRTUAL; 60 } 61 62 @CodeReflection 63 @IR(""" 64 func @"test3" (%0 : EnumAccessTest)java.lang.constant.DirectMethodHandleDesc$Kind -> { 65 %1 : java.lang.constant.DirectMethodHandleDesc$Kind = field.load @"java.lang.constant.DirectMethodHandleDesc$Kind::VIRTUAL()java.lang.constant.DirectMethodHandleDesc$Kind"; 66 return %1; 67 }; 68 """) 69 DirectMethodHandleDesc.Kind test3() { 70 return VIRTUAL; 71 } 72 }