Skip to content

Commit d4da3fd

Browse files
committed
Fix style
1 parent e7f23a4 commit d4da3fd

File tree

4 files changed

+56
-66
lines changed

4 files changed

+56
-66
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
6161
import com.oracle.graal.python.builtins.objects.cext.CApiGuards;
6262
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
63-
import com.oracle.graal.python.builtins.objects.cext.CExtNodes.CastToJavaDoubleNode;
6463
import com.oracle.graal.python.builtins.objects.cext.CExtNodes.PRaiseNativeNode;
6564
import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PrimitiveNativeWrapper;
6665
import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
@@ -72,8 +71,6 @@
7271
import com.oracle.graal.python.nodes.PNodeWithContext;
7372
import com.oracle.graal.python.nodes.PRaiseNode;
7473
import com.oracle.graal.python.nodes.SpecialMethodNames;
75-
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
76-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
7774
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
7875
import com.oracle.graal.python.nodes.util.CannotCastException;
7976
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -277,54 +277,50 @@ Object execute(Object[] arguments,
277277
PythonModule module = factory.createPythonModule(mName);
278278

279279
// process HPy methods
280-
{
281-
Object moduleDefines = callGetterNode.call(context, GRAAL_HPY_MODULE_GET_DEFINES, moduleDef);
282-
if (!ptrLib.hasArrayElements(moduleDefines)) {
283-
throw raiseNode.raise(PythonBuiltinClassType.SystemError, "field 'defines' did not return an array");
284-
}
280+
Object moduleDefines = callGetterNode.call(context, GRAAL_HPY_MODULE_GET_DEFINES, moduleDef);
281+
if (!ptrLib.hasArrayElements(moduleDefines)) {
282+
throw raiseNode.raise(PythonBuiltinClassType.SystemError, "field 'defines' did not return an array");
283+
}
285284

286-
long nModuleDefines = ptrLib.getArraySize(moduleDefines);
287-
for (long i = 0; i < nModuleDefines; i++) {
288-
Object moduleDefine = ptrLib.readArrayElement(moduleDefines, i);
289-
int kind = castToJavaIntNode.execute(callGetterNode.call(context, GRAAL_HPY_DEF_GET_KIND, moduleDefine));
290-
switch (kind) {
291-
case GraalHPyDef.HPY_DEF_KIND_METH:
292-
Object methodDef = callGetterNode.call(context, GRAAL_HPY_DEF_GET_METH, moduleDefine);
293-
PBuiltinFunction fun = addFunctionNode.execute(context, null, methodDef);
294-
PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
295-
writeAttrToMethodNode.execute(method, SpecialAttributeNames.__MODULE__, mName);
296-
writeAttrNode.execute(module, fun.getName(), method);
297-
break;
298-
case GraalHPyDef.HPY_DEF_KIND_SLOT:
299-
case GraalHPyDef.HPY_DEF_KIND_MEMBER:
300-
case GraalHPyDef.HPY_DEF_KIND_GETSET:
301-
// silently ignore
302-
// TODO(fa): maybe we should log a warning
303-
break;
304-
default:
305-
assert false : "unknown definition kind";
306-
}
285+
long nModuleDefines = ptrLib.getArraySize(moduleDefines);
286+
for (long i = 0; i < nModuleDefines; i++) {
287+
Object moduleDefine = ptrLib.readArrayElement(moduleDefines, i);
288+
int kind = castToJavaIntNode.execute(callGetterNode.call(context, GRAAL_HPY_DEF_GET_KIND, moduleDefine));
289+
switch (kind) {
290+
case GraalHPyDef.HPY_DEF_KIND_METH:
291+
Object methodDef = callGetterNode.call(context, GRAAL_HPY_DEF_GET_METH, moduleDefine);
292+
PBuiltinFunction fun = addFunctionNode.execute(context, null, methodDef);
293+
PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
294+
writeAttrToMethodNode.execute(method, SpecialAttributeNames.__MODULE__, mName);
295+
writeAttrNode.execute(module, fun.getName(), method);
296+
break;
297+
case GraalHPyDef.HPY_DEF_KIND_SLOT:
298+
case GraalHPyDef.HPY_DEF_KIND_MEMBER:
299+
case GraalHPyDef.HPY_DEF_KIND_GETSET:
300+
// silently ignore
301+
// TODO(fa): maybe we should log a warning
302+
break;
303+
default:
304+
assert false : "unknown definition kind";
307305
}
308306
}
309307

310308
// process legacy methods
311-
{
312-
Object legacyMethods = callGetterNode.call(context, GRAAL_HPY_MODULE_GET_LEGACY_METHODS, moduleDef);
313-
// the field 'legacy_methods' may be 'NULL'
314-
if (!ptrLib.isNull(legacyMethods)) {
315-
if (!ptrLib.hasArrayElements(legacyMethods)) {
316-
throw raiseNode.raise(PythonBuiltinClassType.SystemError, "field 'legacyMethods' did not return an array");
317-
}
318-
319-
long nLegacyMethods = ptrLib.getArraySize(legacyMethods);
320-
for (long i = 0; i < nLegacyMethods; i++) {
321-
Object legacyMethod = ptrLib.readArrayElement(legacyMethods, i);
322-
323-
PBuiltinFunction fun = addLegacyMethodNode.execute(context, legacyMethod);
324-
PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
325-
writeAttrToMethodNode.execute(method.getStorage(), SpecialAttributeNames.__MODULE__, mName);
326-
writeAttrNode.execute(module, fun.getName(), method);
327-
}
309+
Object legacyMethods = callGetterNode.call(context, GRAAL_HPY_MODULE_GET_LEGACY_METHODS, moduleDef);
310+
// the field 'legacy_methods' may be 'NULL'
311+
if (!ptrLib.isNull(legacyMethods)) {
312+
if (!ptrLib.hasArrayElements(legacyMethods)) {
313+
throw raiseNode.raise(PythonBuiltinClassType.SystemError, "field 'legacyMethods' did not return an array");
314+
}
315+
316+
long nLegacyMethods = ptrLib.getArraySize(legacyMethods);
317+
for (long i = 0; i < nLegacyMethods; i++) {
318+
Object legacyMethod = ptrLib.readArrayElement(legacyMethods, i);
319+
320+
PBuiltinFunction fun = addLegacyMethodNode.execute(context, legacyMethod);
321+
PBuiltinMethod method = factory.createBuiltinMethod(module, fun);
322+
writeAttrToMethodNode.execute(method.getStorage(), SpecialAttributeNames.__MODULE__, mName);
323+
writeAttrNode.execute(module, fun.getName(), method);
328324
}
329325
}
330326

@@ -550,7 +546,7 @@ Object execute(Object[] arguments,
550546
}
551547

552548
try {
553-
Object result = invokeNode.execute(getCallTarget(this, language), pythonArguments);
549+
Object result = invokeNode.execute(getCallTarget(language), pythonArguments);
554550
return asHandleNode.execute(result);
555551
} catch (PException e) {
556552
transformExceptionToNativeNode.execute(e);
@@ -581,27 +577,28 @@ private void checkArguments(Object[] arguments) throws ArityException {
581577
}
582578
}
583579

584-
private RootCallTarget getCallTarget(GraalHPyArithmetic receiver, PythonLanguage language) {
585-
RootCallTarget callTarget = receiver.callTarget;
580+
private RootCallTarget getCallTarget(PythonLanguage language) {
586581
if (callTarget == null) {
587582
CompilerDirectives.transferToInterpreterAndInvalidate();
588583
callTarget = createCallTarget(language);
589-
receiver.callTarget = callTarget;
590584
}
591585
return callTarget;
592586
}
593587

594588
@TruffleBoundary
595589
private RootCallTarget createCallTarget(PythonLanguage language) {
596590
Pair<PythonLanguage, Object> key = Pair.create(language, getOp());
597-
WeakReference<RootCallTarget> ctRef = weakCallTargetMap.get(key);
598-
RootCallTarget callTarget = ctRef != null ? ctRef.get() : null;
599-
if (callTarget == null) {
600-
callTarget = PythonUtils.getOrCreateCallTarget(new CallArithmeticRootNode(language, unaryOperator, binaryOperator, inplaceOperator, ternaryOperator));
601-
weakCallTargetMap.put(key, new WeakReference<>(callTarget));
591+
RootCallTarget cachedCallTarget;
592+
synchronized (weakCallTargetMap) {
593+
WeakReference<RootCallTarget> ctRef = weakCallTargetMap.get(key);
594+
cachedCallTarget = ctRef != null ? ctRef.get() : null;
595+
if (cachedCallTarget == null) {
596+
cachedCallTarget = PythonUtils.getOrCreateCallTarget(new CallArithmeticRootNode(language, unaryOperator, binaryOperator, inplaceOperator, ternaryOperator));
597+
weakCallTargetMap.put(key, new WeakReference<>(cachedCallTarget));
598+
}
602599
}
603-
assert callTarget != null;
604-
return callTarget;
600+
assert cachedCallTarget != null;
601+
return cachedCallTarget;
605602
}
606603

607604
private Object getOp() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ static HPyProperty doIt(GraalHPyContext context, Object memberDef,
512512
@CachedLanguage PythonLanguage language,
513513
@CachedLibrary("memberDef") InteropLibrary interopLibrary,
514514
@CachedLibrary(limit = "2") InteropLibrary valueLib,
515-
@Cached PCallHPyFunction callHelperNode,
516515
@Cached FromCharPointerNode fromCharPointerNode,
517516
@Cached CastToJavaStringNode castToJavaStringNode,
518517
@Cached ReadAttributeFromObjectNode readAttributeNode,
@@ -835,7 +834,7 @@ public abstract static class HPyCreateLegacySlotNode extends PNodeWithContext {
835834

836835
public abstract HPyProperty execute(GraalHPyContext context, Object enclosingType, Object slotDef);
837836

838-
@Specialization(limit = "1")
837+
@Specialization
839838
static HPyProperty doIt(GraalHPyContext context, Object enclosingType, Object slotDef,
840839
@CachedLibrary(limit = "3") InteropLibrary resultLib,
841840
@Cached HPyAddLegacyMethodNode legacyMethodNode,
@@ -1063,7 +1062,7 @@ static int doUnsignedIntPositive(@SuppressWarnings("unused") GraalHPyContext hpy
10631062
@Specialization(replaces = "doUnsignedIntPositive")
10641063
static long doUnsignedInt(@SuppressWarnings("unused") GraalHPyContext hpyContext, int n) {
10651064
if (n < 0) {
1066-
return ((long) n) & 0xffffffffL;
1065+
return n & 0xffffffffL;
10671066
}
10681067
return n;
10691068
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/InplaceArithmetic.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040
*/
4141
package com.oracle.graal.python.nodes.expression;
4242

43-
import com.oracle.graal.python.nodes.ErrorMessages;
4443
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
4544

46-
import com.oracle.graal.python.util.Supplier;
47-
45+
import com.oracle.graal.python.nodes.ErrorMessages;
4846
import com.oracle.graal.python.nodes.PRaiseNode;
4947
import com.oracle.graal.python.nodes.SpecialMethodNames;
50-
import com.oracle.truffle.api.nodes.Node.Child;
48+
import com.oracle.graal.python.util.Supplier;
5149

5250
public enum InplaceArithmetic {
5351
IAdd(SpecialMethodNames.__IADD__, "+="),
@@ -78,8 +76,7 @@ public enum InplaceArithmetic {
7876
this.operator = operator;
7977
this.isTernary = isTernary;
8078
this.notImplementedHandler = () -> new LookupAndCallInplaceNode.NotImplementedHandler() {
81-
@Child
82-
private PRaiseNode raiseNode = PRaiseNode.create();
79+
@Child private PRaiseNode raiseNode = PRaiseNode.create();
8380

8481
@Override
8582
public Object execute(Object arg, Object arg2) {

0 commit comments

Comments
 (0)