Skip to content

Commit 9e633aa

Browse files
committed
[GR-51153] PEGraphDecoder#handleInvokeWithCallTarget check for a method from an unlinked class is no more valid.
PullRequest: graal/16489
2 parents 53449f9 + 3fd3472 commit 9e633aa

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/PEGraphDecoder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ protected LoopScope handleInvokeWithCallTarget(PEMethodScope methodScope, LoopSc
999999
}
10001000
callTarget = trySimplifyCallTarget(methodScope, invokeData, methodCall);
10011001
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
1002-
if (forceLink && targetMethod.hasBytecodes() && targetMethod.getCode() == null && !targetMethod.getDeclaringClass().isLinked()) {
1002+
if (forceLink && targetMethod.getCodeSize() == -1) {
10031003
targetMethod.getDeclaringClass().link();
10041004
}
10051005
LoopScope inlineLoopScope = trySimplifyInvoke(methodScope, loopScope, invokeData, (MethodCallTargetNode) callTarget);

0 commit comments

Comments
 (0)