Skip to content

Commit 9dc1d91

Browse files
committed
[GR-38998] Avoid deopts after OSR, monomorphize execute calls
PullRequest: graalpython/2293
2 parents 4ad3d86 + 74ef04c commit 9dc1d91

File tree

5 files changed

+560
-222
lines changed

5 files changed

+560
-222
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_imaplib.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_bad_auth_name
44
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_certfile_arg_warn
55
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_enable_UTF8_True_append
6-
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_enable_UTF8_raises_error_if_not_supported
76
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_enable_raises_error_if_no_capability
87
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_enable_raises_error_if_not_AUTH
98
*graalpython.lib-python.3.test.test_imaplib.NewIMAPSSLTests.test_invalid_authentication

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.concurrent.Semaphore;
3939
import java.util.logging.Level;
4040

41-
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
4241
import org.graalvm.options.OptionDescriptors;
4342
import org.graalvm.options.OptionKey;
4443
import org.graalvm.options.OptionValues;
@@ -64,21 +63,22 @@
6463
import com.oracle.graal.python.compiler.CompilationUnit;
6564
import com.oracle.graal.python.compiler.Compiler;
6665
import com.oracle.graal.python.nodes.HiddenAttributes;
67-
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
6866
import com.oracle.graal.python.nodes.PRootNode;
6967
import com.oracle.graal.python.nodes.RootNodeFactory;
68+
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
7069
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
7170
import com.oracle.graal.python.nodes.expression.ExpressionNode;
7271
import com.oracle.graal.python.nodes.util.BadOPCodeNode;
7372
import com.oracle.graal.python.parser.PythonParserImpl;
73+
import com.oracle.graal.python.pegparser.ErrorCallback;
7474
import com.oracle.graal.python.pegparser.FExprParser;
7575
import com.oracle.graal.python.pegparser.InputType;
7676
import com.oracle.graal.python.pegparser.NodeFactoryImp;
7777
import com.oracle.graal.python.pegparser.Parser;
78-
import com.oracle.graal.python.pegparser.ErrorCallback;
7978
import com.oracle.graal.python.pegparser.ParserTokenizer;
8079
import com.oracle.graal.python.pegparser.sst.ExprTy;
8180
import com.oracle.graal.python.pegparser.sst.ModTy;
81+
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
8282
import com.oracle.graal.python.runtime.GilNode;
8383
import com.oracle.graal.python.runtime.PythonContext;
8484
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
@@ -166,6 +166,8 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
166166
public static final int RELEASE_LEVEL_FINAL = 0xF;
167167
public static final int RELEASE_LEVEL = RELEASE_LEVEL_ALPHA;
168168
public static final TruffleString RELEASE_LEVEL_STRING;
169+
public static final TruffleString DEFAULT_FILENAME = tsLiteral("<string>");
170+
169171
static {
170172
switch (RELEASE_LEVEL) {
171173
case RELEASE_LEVEL_ALPHA:
@@ -581,13 +583,22 @@ public SourceSection getSourceSection() {
581583
instance = PythonObjectFactory.getUncached().createBaseException(cls, message, PythonUtils.EMPTY_OBJECT_ARRAY);
582584
final Object[] excAttrs = SyntaxErrorBuiltins.SYNTAX_ERROR_ATTR_FACTORY.create();
583585
SourceSection section = location.getSourceSection();
584-
TruffleString path = toTruffleStringUncached(source.getPath());
585-
excAttrs[SyntaxErrorBuiltins.IDX_FILENAME] = (path != null) ? path : source.getName() != null ? toTruffleStringUncached(source.getName()) : tsLiteral("<string>");
586+
TruffleString filename = toTruffleStringUncached(source.getPath());
587+
if (filename == null) {
588+
filename = toTruffleStringUncached(source.getName());
589+
if (filename == null) {
590+
filename = DEFAULT_FILENAME;
591+
}
592+
}
593+
excAttrs[SyntaxErrorBuiltins.IDX_FILENAME] = filename;
586594
excAttrs[SyntaxErrorBuiltins.IDX_LINENO] = section.getStartLine();
587595
excAttrs[SyntaxErrorBuiltins.IDX_OFFSET] = section.getStartColumn();
588596
// Not very nice. This counts on the implementation in traceback.py where if the value of
589597
// text attribute is NONE, then the line is not printed
590-
final TruffleString text = section.isAvailable() ? toTruffleStringUncached(source.getCharacters(section.getStartLine()).toString()) : null;
598+
Object text = PNone.NONE;
599+
if (section.isAvailable()) {
600+
text = toTruffleStringUncached(source.getCharacters(section.getStartLine()).toString());
601+
}
591602
excAttrs[SyntaxErrorBuiltins.IDX_MSG] = message;
592603
excAttrs[SyntaxErrorBuiltins.IDX_TEXT] = text;
593604
instance.setExceptionAttributes(excAttrs);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.nodes.bytecode;
42+
43+
final class OSRInterpreterState {
44+
public final int stackTop;
45+
public final int loopEndBci;
46+
47+
public OSRInterpreterState(int stackTop, int loopEndBci) {
48+
this.stackTop = stackTop;
49+
this.loopEndBci = loopEndBci;
50+
}
51+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ private void profileFrameSlots(MaterializedFrame generatorFrame) {
163163
}
164164

165165
@Override
166-
public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterState) {
167-
Integer osrStackTop = (Integer) interpreterState;
166+
public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterStateObject) {
167+
OSRInterpreterState interpreterState = (OSRInterpreterState) interpreterStateObject;
168168
MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(osrFrame);
169169
copyStackSlotsIntoVirtualFrame(generatorFrame, osrFrame);
170-
copyOSRStackRemainderIntoVirtualFrame(generatorFrame, osrFrame, osrStackTop);
171-
return rootNode.executeFromBci(osrFrame, generatorFrame, osrFrame, this, target, osrStackTop);
170+
copyOSRStackRemainderIntoVirtualFrame(generatorFrame, osrFrame, interpreterState.stackTop);
171+
return rootNode.executeFromBci(osrFrame, generatorFrame, osrFrame, this, target, interpreterState.stackTop, interpreterState.loopEndBci);
172172
}
173173

174174
@ExplodeLoop
@@ -205,7 +205,7 @@ public Object execute(VirtualFrame frame) {
205205
stackFrame = frame;
206206
}
207207
try {
208-
return rootNode.executeFromBci(frame, generatorFrame, stackFrame, this, resumeBci, resumeStackTop);
208+
return rootNode.executeFromBci(frame, generatorFrame, stackFrame, this, resumeBci, resumeStackTop, Integer.MAX_VALUE);
209209
} finally {
210210
calleeContext.exit(frame, this);
211211
}

0 commit comments

Comments
 (0)