Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ It consists of: Java (Truffle) + C (CPython C-API compatibility) + Python stdlib

## CONVENTIONS (DEVIATIONS)
- `mx` is the primary build/test entrypoint; suite definition lives in `mx.graalpython/suite.py`.
- By default always pass `--java-home=lookup:default` to `mx` to select the default JDK.
- `black` is configured but intentionally **disabled** for this repo (root `pyproject.toml`); line length is 120 and version locked to `23` for consistency.
- Formatting/linting is enforced via **pre-commit** with repo-specific hooks (Eclipse formatter, checkstyle, copyright), and pylint only on `mx.graalpython/*.py`.
- Large generated/build outputs exist in-tree (`mxbuild/`, `*.dist/`); do not use them as the source of truth when navigating code.
Expand Down Expand Up @@ -71,7 +72,6 @@ It consists of: Java (Truffle) + C (CPython C-API compatibility) + Python stdlib
`mx python-gate --tags style`
* Building standalones for benchmarking
- use `mx --env native-ee sforceimports && mx --env native-ee checkout-downstream compiler graal-enterprise` to get the right revisions
- use `mx -p ../graal/vm fetch-jdk -jdk-id labsjdk-ce-latest` and set JAVA_HOME as per that command's output
- use `mx --env jvm-ee-libgraal` and `mx --env native-ee` to build the JAVA and NATIVE standalone distributions

## NOTES
Expand Down
1 change: 1 addition & 0 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper.ToNativeStorageNode;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CApiNativeStub;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonObjectReference;
import com.oracle.graal.python.builtins.objects.cext.copying.NativeLibraryLocator;
Expand Down Expand Up @@ -1275,9 +1276,8 @@ abstract static class IsWeakHandleTableRef extends PythonUnaryBuiltinNode {
@Specialization
@TruffleBoundary
static boolean doGeneric(int id) {
Object ref = CApiTransitions.nativeStubLookupGet(PythonContext.get(null).handleContext, 0, id);
assert ref == null || ref instanceof PythonAbstractObject || ref instanceof PythonObjectReference;
return ref instanceof PythonAbstractObject || ref != null && ((PythonObjectReference) ref).isStrongReference();
CApiNativeStub ref = CApiTransitions.nativeStubLookupGet(PythonContext.get(null).handleContext, 0, id);
return ref instanceof PythonAbstractObject || ref instanceof PythonObjectReference pythonObjectReference && pythonObjectReference.isStrongReference();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CApiNativeStub;
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetIterator;
Expand Down Expand Up @@ -186,7 +187,7 @@

@ImportStatic(SpecialMethodNames.class)
@ExportLibrary(InteropLibrary.class)
public abstract class PythonAbstractObject extends DynamicObject implements TruffleObject, Comparable<Object> {
public abstract class PythonAbstractObject extends DynamicObject implements TruffleObject, CApiNativeStub, Comparable<Object> {
public static final long UNINITIALIZED = -1;
public static final long NATIVE_POINTER_FREED = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public static final class HandleContext {

public HandleContext(boolean useShadowTable) {
nativeStubLookupShadowTable = useShadowTable ? new HashMap<>() : null;
nativeStubLookup = new Object[DEFAULT_CAPACITY];
nativeStubLookup = new CApiNativeStub[DEFAULT_CAPACITY];
nativeStubLookupFreeStack = new HandleStack(DEFAULT_CAPACITY);
nativeStubLookupFreeStack.pushRange(FIRST_VALID_INDEX, DEFAULT_CAPACITY);
nativeTypeLookup = new IdReference<?>[DEFAULT_CAPACITY];
Expand All @@ -232,8 +232,8 @@ public HandleContext(boolean useShadowTable) {

public IdReference<?>[] nativeTypeLookup;

private final HashMap<Long, Object> nativeStubLookupShadowTable;
public Object[] nativeStubLookup;
private final HashMap<Long, CApiNativeStub> nativeStubLookupShadowTable;
public CApiNativeStub[] nativeStubLookup;
public final HandleStack nativeStubLookupFreeStack;

public final Set<NativeStorageReference> nativeStorageReferences = new HashSet<>();
Expand Down Expand Up @@ -281,10 +281,16 @@ public IdReference(HandleContext handleContext, T referent) {

}

/**
* Marker interface for types that can be looked up.
*/
public interface CApiNativeStub {
}

/**
* A weak and unique reference to a native wrapper of a reference counted managed object.
*/
public static final class PythonObjectReference extends IdReference<PythonObject> {
public static final class PythonObjectReference extends IdReference<PythonObject> implements CApiNativeStub {
/**
* This reference forces the wrapper to remain alive, and can be set to null when the
* refcount falls to {@link PythonObject#MANAGED_REFCNT}.
Expand Down Expand Up @@ -931,7 +937,7 @@ public static void freeNativeObjectStubs(HandleContext handleContext) {
assert PythonContext.get(null).ownsGil();
assert PythonContext.get(null).isFinalizing();
for (int i = HandleContext.FIRST_VALID_INDEX; i < handleContext.nativeStubLookup.length; i++) {
Object ref = handleContext.nativeStubLookup[i];
CApiNativeStub ref = handleContext.nativeStubLookup[i];
// not all slots of the handle table are currently used
if (ref == null) {
continue;
Expand Down Expand Up @@ -1152,14 +1158,14 @@ private static boolean isValidTypeLookupEntry(Object entry, long ptr) {
entry instanceof PythonNativeClass nativeClass && nativeClass.getPtr() == ptr;
}

public static Object nativeStubLookupGet(HandleContext context, long pointer, int idx) {
public static CApiNativeStub nativeStubLookupGet(HandleContext context, long pointer, int idx) {
if (idx <= 0) {
if (PythonContext.DEBUG_CAPI && HandleContext.getShadowTable(context.nativeStubLookupShadowTable, pointer) != null) {
throw CompilerDirectives.shouldNotReachHere();
}
return null;
}
Object result = context.nativeStubLookup[idx];
CApiNativeStub result = context.nativeStubLookup[idx];
if (PythonContext.DEBUG_CAPI && HandleContext.getShadowTable(context.nativeStubLookupShadowTable, pointer) != result) {
throw CompilerDirectives.shouldNotReachHere();
}
Expand Down Expand Up @@ -1197,14 +1203,14 @@ private static int resizeNativeStubLookupTable(HandleContext context) throws Ove
return context.nativeStubLookupFreeStack.pop();
}

private static int nativeStubLookupPut(HandleContext context, int idx, Object value, long pointer) {
private static int nativeStubLookupPut(HandleContext context, int idx, CApiNativeStub value, long pointer) {
assert idx > 0;
assert HandlePointerConverter.pointsToPyHandleSpace(pointer);
assert value instanceof PythonObject || value instanceof PythonObjectReference || CApiContext.isSpecialSingleton(value);
assert context.nativeStubLookup[idx] == null || context.nativeStubLookup[idx] == value;
context.nativeStubLookup[idx] = value;
if (PythonContext.DEBUG_CAPI) {
Object prev = HandleContext.putShadowTable(context.nativeStubLookupShadowTable, pointer, value);
CApiNativeStub prev = HandleContext.putShadowTable(context.nativeStubLookupShadowTable, pointer, value);
if (prev != null && prev != value) {
throw CompilerDirectives.shouldNotReachHere();
}
Expand All @@ -1219,7 +1225,7 @@ private static int nativeStubLookupReplaceByWeak(HandleContext context, int idx,
assert context.nativeStubLookup[idx] == value.get();
context.nativeStubLookup[idx] = value;
if (PythonContext.DEBUG_CAPI) {
Object prev = HandleContext.putShadowTable(context.nativeStubLookupShadowTable, pointer, value);
CApiNativeStub prev = HandleContext.putShadowTable(context.nativeStubLookupShadowTable, pointer, value);
if (prev != value.get()) {
throw CompilerDirectives.shouldNotReachHere();
}
Expand All @@ -1232,9 +1238,9 @@ public static void nativeStubLookupRemove(HandleContext context, PythonObjectRef
nativeStubLookupRemove(context, ref.handleTableIndex);
}

public static Object nativeStubLookupRemove(HandleContext context, int idx) {
public static CApiNativeStub nativeStubLookupRemove(HandleContext context, int idx) {
assert idx >= HandleContext.FIRST_VALID_INDEX;
Object result = context.nativeStubLookup[idx];
CApiNativeStub result = context.nativeStubLookup[idx];
assert result instanceof PythonObjectReference || result instanceof PythonObject || CApiContext.isSpecialSingleton(result);
context.nativeStubLookup[idx] = null;
context.nativeStubLookupFreeStack.push(idx);
Expand Down Expand Up @@ -1540,7 +1546,7 @@ static long doGeneric(Node inliningTarget, PythonAbstractObject object, Object t
// accidentally maps to some valid object.
assert idx > 0;
CStructAccess.writeIntField(stubPointer, CFields.GraalPyObject__handle_table_index, idx);
Object ref;
CApiNativeStub ref;
if (initialRefCount > MANAGED_REFCNT) {
ref = object;

Expand Down Expand Up @@ -2133,7 +2139,7 @@ static Object doGeneric(Node inliningTarget, long pointer, boolean needsTransfer
return HandlePointerConverter.pointerToDouble(pointer);
}
int idx = readIntField(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
Object reference = nativeStubLookupGet(handleContext, pointer, idx);
CApiNativeStub reference = nativeStubLookupGet(handleContext, pointer, idx);
if (reference instanceof PythonAbstractObject) {
result = (PythonAbstractObject) reference;
} else if (reference instanceof PythonObjectReference pythonObjectReference) {
Expand Down Expand Up @@ -2331,7 +2337,7 @@ static Object doNonWrapper(long pointer, boolean stealing,
return HandlePointerConverter.pointerToDouble(pointer);
}
int idx = readIntField(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
Object reference = nativeStubLookupGet(handleContext, pointer, idx);
CApiNativeStub reference = nativeStubLookupGet(handleContext, pointer, idx);
if (reference instanceof PythonAbstractObject) {
pythonAbstractObject = (PythonAbstractObject) reference;
} else if (reference instanceof PythonObjectReference pythonObjectReference) {
Expand Down Expand Up @@ -2411,7 +2417,7 @@ static Object doLong(Node inliningTarget, long pointer,
}
int idx = readIntField(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
PythonObject pythonObject;
Object reference = nativeStubLookupGet(handleContext, pointer, idx);
CApiNativeStub reference = nativeStubLookupGet(handleContext, pointer, idx);
if (reference instanceof PythonObject) {
pythonObject = (PythonObject) reference;
} else if (reference instanceof PythonObjectReference pythonObjectReference) {
Expand Down Expand Up @@ -2810,7 +2816,7 @@ static void doGeneric(Node inliningTarget, HandleContext handleContext, long tag
assert !HandlePointerConverter.pointsToPyIntHandle(taggedPointer);
assert !HandlePointerConverter.pointsToPyFloatHandle(taggedPointer);

Object ref = nativeStubLookupGet(handleContext, taggedPointer, handleTableIndex);
CApiNativeStub ref = nativeStubLookupGet(handleContext, taggedPointer, handleTableIndex);
if (ref instanceof PythonObjectReference pythonObjectReference) {
hasWeakRef.enter(inliningTarget);
handlePythonObjectReference(inliningTarget, pythonObjectReference, taggedPointer, handleTableIndex,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -45,7 +45,7 @@
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.truffle.PythonIntToLongTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateCached;
Expand All @@ -57,7 +57,7 @@
* generated code.
*/
@GenerateCached(false)
@TypeSystemReference(PythonIntegerTypes.class)
@TypeSystemReference(PythonIntToLongTypes.class)
public abstract class PyNumberAddFastPathsBase extends BinaryOpNode {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -41,7 +41,7 @@
package com.oracle.graal.python.lib.fastpath;

import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.truffle.PythonIntToLongTypes;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.TypeSystemReference;
Expand All @@ -51,7 +51,7 @@
* generated code.
*/
@GenerateCached(false)
@TypeSystemReference(PythonIntegerTypes.class)
@TypeSystemReference(PythonIntToLongTypes.class)
public abstract class PyNumberFloorDivideFastPathsBase extends BinaryOpNode {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -45,7 +45,7 @@
import com.oracle.graal.python.PythonLanguage;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.truffle.PythonIntToLongTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateCached;
Expand All @@ -58,7 +58,7 @@
* generated code.
*/
@GenerateCached(false)
@TypeSystemReference(PythonIntegerTypes.class)
@TypeSystemReference(PythonIntToLongTypes.class)
public abstract class PyNumberMultiplyFastPathsBase extends BinaryOpNode {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -41,7 +41,7 @@
package com.oracle.graal.python.lib.fastpath;

import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.truffle.PythonIntToLongTypes;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.TypeSystemReference;
Expand All @@ -51,7 +51,7 @@
* generated code.
*/
@GenerateCached(false)
@TypeSystemReference(PythonIntegerTypes.class)
@TypeSystemReference(PythonIntToLongTypes.class)
public abstract class PyNumberRemainderFastPathsBase extends BinaryOpNode {

@Specialization(guards = "right != 0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -44,7 +44,7 @@
import com.oracle.graal.python.builtins.objects.ints.IntBuiltins;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.truffle.PythonIntToLongTypes;
import com.oracle.graal.python.runtime.object.PFactory;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
Expand All @@ -54,7 +54,7 @@
import com.oracle.truffle.api.nodes.Node;

@GenerateCached(false)
@TypeSystemReference(PythonIntegerTypes.class)
@TypeSystemReference(PythonIntToLongTypes.class)
public abstract class PyNumberSubtractFastPathsBase extends BinaryOpNode {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -42,7 +42,7 @@

import com.oracle.graal.python.builtins.objects.ints.IntBuiltins;
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
import com.oracle.graal.python.nodes.truffle.PythonIntToLongTypes;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
Expand All @@ -53,7 +53,7 @@
* generated code.
*/
@GenerateCached(false)
@TypeSystemReference(PythonIntegerTypes.class)
@TypeSystemReference(PythonIntToLongTypes.class)
@ImportStatic(IntBuiltins.TrueDivNode.class)
public abstract class PyNumberTrueDivideFastPathsBase extends BinaryOpNode {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,6 @@ public static boolean isBuiltinWithObjectOrModuleGetattro(Shape cachedShape) {
}

@ForceQuickening
@StoreBytecodeIndex // looking up attribute in MRO may have side effects
@Specialization(guards = {
"!hasMaterializedDict(cachedShape)", "managedClass != null || isBuiltinWithObjectOrModuleGetattro(cachedShape)", //
"getter != null", "getter.accepts(receiver)", //
Expand Down
Loading
Loading