|
| 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. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package jdk.graal.compiler.truffle.test; |
| 26 | + |
| 27 | +import com.oracle.truffle.api.frame.VirtualFrame; |
| 28 | +import com.oracle.truffle.api.nodes.RootNode; |
| 29 | +import com.oracle.truffle.compiler.TruffleCompilationTask; |
| 30 | +import com.oracle.truffle.runtime.OptimizedCallTarget; |
| 31 | +import jdk.graal.compiler.truffle.TruffleCompilerImpl; |
| 32 | +import jdk.vm.ci.meta.ResolvedJavaType; |
| 33 | +import org.junit.Test; |
| 34 | + |
| 35 | +public class ClassLinkedByCompilerTest extends PartialEvaluationTest { |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testClassLinkedByCompiler() { |
| 39 | + RootNode root = new RootNodeImpl(); |
| 40 | + OptimizedCallTarget compilable = (OptimizedCallTarget) root.getCallTarget(); |
| 41 | + TruffleCompilationTask task = newTask(); |
| 42 | + TruffleCompilerImpl compiler = getTruffleCompiler(compilable); |
| 43 | + ResolvedJavaType unlinked = getMetaAccess().lookupJavaType(Unlinked.class); |
| 44 | + assertFalse("Class should not be linked before compilation.", unlinked.isLinked()); |
| 45 | + compiler.doCompile(task, compilable, null); |
| 46 | + assertTrue("Class must be linked during compilation.", unlinked.isLinked()); |
| 47 | + } |
| 48 | + |
| 49 | + static final class RootNodeImpl extends RootNode { |
| 50 | + |
| 51 | + RootNodeImpl() { |
| 52 | + super(null); |
| 53 | + } |
| 54 | + |
| 55 | + public Object execute(VirtualFrame frame) { |
| 56 | + return Unlinked.call(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + static final class Unlinked { |
| 61 | + static boolean call() { |
| 62 | + return true; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments