Skip to content

Commit df96ec9

Browse files
committed
[GR-11445] Report allocations.
PullRequest: graalpython/174
2 parents d5f83db + 44b544e commit df96ec9

File tree

18 files changed

+67
-90
lines changed

18 files changed

+67
-90
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
143143
import com.oracle.truffle.api.TruffleFile;
144144
import com.oracle.truffle.api.TruffleLanguage.Env;
145-
import com.oracle.truffle.api.nodes.Node;
146145
import com.oracle.truffle.api.source.Source;
147146

148147
/**
@@ -435,41 +434,16 @@ public PythonClass getErrorClass(PythonErrorType type) {
435434
}
436435

437436
@Override
438-
public PException raise(PBaseException exception, Node node) {
439-
PException pException = new PException(exception, node);
440-
exception.setException(pException);
441-
throw pException;
442-
}
443-
444-
@Override
445-
public PException raise(PythonErrorType type, Node node, String format, Object... args) {
437+
@TruffleBoundary
438+
public PException raise(PythonErrorType type, String format, Object... args) {
446439
PBaseException instance;
447440
PythonClass exceptionType = getErrorClass(type);
448441
if (format != null) {
449442
instance = factory.createBaseException(exceptionType, format, args);
450443
} else {
451-
instance = factory.createBaseException(exceptionType, factory.createEmptyTuple());
444+
instance = factory.createBaseException(exceptionType);
452445
}
453-
throw raise(instance, node);
454-
}
455-
456-
@Override
457-
public PException raise(PythonErrorType type, String format, Object... args) {
458-
return raise(type, null, format, args);
459-
}
460-
461-
@Override
462-
public PException raise(PythonErrorType type) {
463-
throw raise(factory.createBaseException(getErrorClass(type)), null);
464-
}
465-
466-
@Override
467-
public PException raise(PythonClass exceptionType, Node node) {
468-
throw raise(factory.createBaseException(exceptionType), node);
469-
}
470-
471-
public PException raise(PythonErrorType type, Node node) {
472-
throw raise(factory.createBaseException(getErrorClass(type)), node);
446+
throw PException.fromObject(instance, null);
473447
}
474448

475449
private void publishBuiltinModules() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private PComplex convertStringToComplex(String str, PythonClass cls) {
314314
}
315315

316316
if (s == n) {
317-
throw getCore().raise(ValueError, "empty string for complex()");
317+
throw raise(ValueError, "empty string for complex()");
318318
}
319319

320320
double z = -1.0;
@@ -379,7 +379,7 @@ private PComplex convertStringToComplex(String str, PythonClass cls) {
379379
int end = endDouble(str, s);
380380
z = Double.valueOf(str.substring(s, end)).doubleValue();
381381
if (z == Double.POSITIVE_INFINITY) {
382-
throw getCore().raise(ValueError, String.format("float() out of range: %.150s", str));
382+
throw raise(ValueError, String.format("float() out of range: %.150s", str));
383383
}
384384

385385
s = end;
@@ -407,7 +407,7 @@ private PComplex convertStringToComplex(String str, PythonClass cls) {
407407
} while (s < n && !swError);
408408

409409
if (swError) {
410-
throw getCore().raise(ValueError, "malformed string for complex() %s", str.substring(s));
410+
throw raise(ValueError, "malformed string for complex() %s", str.substring(s));
411411
}
412412

413413
return factory().createComplex(cls, x, y);
@@ -640,7 +640,7 @@ private double convertStringToDouble(String str) {
640640
for (int i = 0; i < n; i++) {
641641
char ch = str.charAt(i);
642642
if (ch == '\u0000') {
643-
throw getCore().raise(ValueError, "empty string for complex()");
643+
throw raise(ValueError, "empty string for complex()");
644644
}
645645
if (Character.isDigit(ch)) {
646646
if (s == null) {
@@ -667,7 +667,7 @@ private double convertStringToDouble(String str) {
667667
return Double.valueOf(sval).doubleValue();
668668
} catch (NumberFormatException exc) {
669669
// throw Py.ValueError("invalid literal for __float__: " + str);
670-
throw getCore().raise(ValueError, "could not convert string to float: %s", str);
670+
throw raise(ValueError, "could not convert string to float: %s", str);
671671
}
672672
}
673673

@@ -814,7 +814,7 @@ private Object stringToInt(String num, int base) {
814814
return bi.intValue();
815815
}
816816
} else {
817-
throw getCore().raise(ValueError, "base is out of range for int()");
817+
throw raise(ValueError, "base is out of range for int()");
818818
}
819819
}
820820

@@ -836,7 +836,7 @@ private Object toInt(Object arg1, Object arg2) {
836836
if (arg1 instanceof String && arg2 instanceof Integer) {
837837
return stringToInt((String) arg1, (Integer) arg2);
838838
} else {
839-
throw getCore().raise(ValueError, "invalid base or val for int()");
839+
throw raise(ValueError, "invalid base or val for int()");
840840
}
841841
}
842842

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ public Object repr(Object obj,
12461246
if (isString.profile(result instanceof String) || isPString.profile(result instanceof PString)) {
12471247
return result;
12481248
}
1249-
throw getCore().raise(TypeError, "__repr__ returned non-string (type %p)", obj);
1249+
throw raise(TypeError, "__repr__ returned non-string (type %p)", obj);
12501250
}
12511251
}
12521252

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ String decodeBytes(ByteBuffer bytes, String encoding, String errors) {
441441
CharBuffer decoded = charset.newDecoder().onMalformedInput(errorAction).onUnmappableCharacter(errorAction).decode(bytes);
442442
return String.valueOf(decoded);
443443
} catch (IllegalArgumentException e) {
444-
throw this.getCore().raise(LookupError, "unknown encoding: %s", encoding);
444+
throw this.raise(LookupError, "unknown encoding: %s", encoding);
445445
} catch (CharacterCodingException e) {
446446
throw raise(UnicodeDecodeError, "%s", e.getMessage());
447447
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ protected GetStackTraceRootNode(PythonLanguage language) {
226226
@Override
227227
public Object execute(VirtualFrame frame) {
228228
CompilerDirectives.transferToInterpreter();
229-
throw contextRef.get().getCore().raise(ValueError);
229+
throw contextRef.get().getCore().raise(ValueError, null);
230230
}
231231

232232
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ Object run(@SuppressWarnings("unused") PythonClass typ, PBaseException val, @Sup
325325
if (val.getException() != null) {
326326
getContext().setCurrentException(val.getException());
327327
} else {
328-
PException pException = new PException(val, this);
329-
val.setException(pException);
328+
PException pException = PException.fromObject(val, this);
330329
getContext().setCurrentException(pException);
331330
}
332331
return PNone.NONE;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ Object run(PDict self, Object key,
319319
if (delItemNode.execute(self, self.getDictStorage(), key)) {
320320
return PNone.NONE;
321321
}
322-
throw getCore().raise(KeyError, this, "%s", key);
322+
throw raise(KeyError, "%s", key);
323323
}
324324
}
325325

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, @Suppress
155155
@Cached("create(__CALL__)") LookupAndCallVarargsNode callTyp) {
156156
Object instance = callTyp.execute(frame, typ, new Object[0]);
157157
if (instance instanceof PBaseException) {
158-
PException pException = new PException((PBaseException) instance, this);
159-
((PBaseException) instance).setException(pException);
158+
PException pException = PException.fromObject((PBaseException) instance, this);
160159
PArguments.setSpecialArgument(self.getArguments(), pException);
161160
} else {
162161
throw raise(TypeError, "exceptions must derive from BaseException");
@@ -169,8 +168,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, PTuple va
169168
@Cached("create(__CALL__)") LookupAndCallVarargsNode callTyp) {
170169
Object instance = callTyp.execute(frame, typ, val.getArray());
171170
if (instance instanceof PBaseException) {
172-
PException pException = new PException((PBaseException) instance, this);
173-
((PBaseException) instance).setException(pException);
171+
PException pException = PException.fromObject((PBaseException) instance, this);
174172
PArguments.setSpecialArgument(self.getArguments(), pException);
175173
} else {
176174
throw raise(TypeError, "exceptions must derive from BaseException");
@@ -183,8 +181,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, Object va
183181
@Cached("create(__CALL__)") LookupAndCallVarargsNode callTyp) {
184182
Object instance = callTyp.execute(frame, typ, new Object[]{val});
185183
if (instance instanceof PBaseException) {
186-
PException pException = new PException((PBaseException) instance, this);
187-
((PBaseException) instance).setException(pException);
184+
PException pException = PException.fromObject((PBaseException) instance, this);
188185
PArguments.setSpecialArgument(self.getArguments(), pException);
189186
} else {
190187
throw raise(TypeError, "exceptions must derive from BaseException");
@@ -194,16 +191,14 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, Object va
194191

195192
@Specialization
196193
Object sendThrow(PGenerator self, PBaseException instance, @SuppressWarnings("unused") PNone val, @SuppressWarnings("unused") PNone tb) {
197-
PException pException = new PException(instance, this);
198-
instance.setException(pException);
194+
PException pException = PException.fromObject(instance, this);
199195
PArguments.setSpecialArgument(self.getArguments(), pException);
200196
return resumeGenerator(self);
201197
}
202198

203199
@Specialization
204200
Object sendThrow(PGenerator self, @SuppressWarnings("unused") PythonClass typ, PBaseException instance, PTraceback tb) {
205-
PException pException = new PException(instance, this);
206-
instance.setException(pException);
201+
PException pException = PException.fromObject(instance, this);
207202
instance.setTraceback(tb);
208203
PArguments.setSpecialArgument(self.getArguments(), pException);
209204
return resumeGenerator(self);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptorTypeBuiltins.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
5656
import com.oracle.graal.python.builtins.objects.type.PythonClass;
5757
import com.oracle.graal.python.nodes.PGuards;
58+
import com.oracle.graal.python.nodes.PNodeWithContext;
5859
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
5960
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
6061
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6162
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6263
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6364
import com.oracle.graal.python.nodes.object.GetClassNode;
64-
import com.oracle.graal.python.runtime.PythonCore;
6565
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6666
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6767
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -94,7 +94,7 @@ abstract static class GetSetGetNode extends PythonTernaryBuiltinNode {
9494
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L149
9595
@Specialization
9696
Object get(GetSetDescriptor descr, Object obj, PythonClass type) {
97-
if (descr_check(getCore(), descr, obj, type)) {
97+
if (descr_check(this, descr, obj, type)) {
9898
return descr;
9999
}
100100
if (descr.getGet() != null) {
@@ -116,7 +116,7 @@ abstract static class GetSetSetNode extends PythonTernaryBuiltinNode {
116116
@Specialization
117117
Object set(GetSetDescriptor descr, Object obj, Object value) {
118118
// the noneType is not important here - there are no setters on None
119-
if (descr_check(getCore(), descr, obj, getClassNode.execute(obj))) {
119+
if (descr_check(this, descr, obj, getClassNode.execute(obj))) {
120120
return descr;
121121
}
122122
if (descr.getSet() != null) {
@@ -129,7 +129,7 @@ Object set(GetSetDescriptor descr, Object obj, Object value) {
129129
}
130130

131131
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L70
132-
private static boolean descr_check(PythonCore core, GetSetDescriptor descr, Object obj, PythonClass type) {
132+
private static boolean descr_check(PNodeWithContext node, GetSetDescriptor descr, Object obj, PythonClass type) {
133133
if (PGuards.isNone(obj)) {
134134
if (!(type instanceof PythonBuiltinClass) || ((PythonBuiltinClass) type).getType() != PythonBuiltinClassType.PNone) {
135135
return true;
@@ -141,6 +141,6 @@ private static boolean descr_check(PythonCore core, GetSetDescriptor descr, Obje
141141
}
142142
}
143143

144-
throw core.raise(TypeError, "descriptor '%s' for '%s' objects doesn't apply to '%s' object", descr.getName(), descr.getType().getName(), type.getName());
144+
throw node.raise(TypeError, "descriptor '%s' for '%s' objects doesn't apply to '%s' object", descr.getName(), descr.getType().getName(), type.getName());
145145
}
146146
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ private void shiftError(long shiftCount) {
980980
if (shiftCount >= Integer.SIZE) {
981981
throw new ArithmeticException("integer overflow");
982982
} else if (shiftCount < 0) {
983-
throw getCore().raise(ValueError, "negative shift count");
983+
throw raise(ValueError, "negative shift count");
984984
}
985985
}
986986

0 commit comments

Comments
 (0)