Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
}
}
}
if (Boolean.getBoolean("python.DetailedAsserts")) {
addRelaunchArg("--vm.Dpython.DetailedAsserts=true");
}

// According to CPython if no arguments are given, they contain an empty string.
if (programArgs.isEmpty()) {
Expand Down
5 changes: 3 additions & 2 deletions graalpython/com.oracle.graal.python.test/src/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,9 +1599,10 @@ def main_run(args):
if IS_GRAALPY:
if not get_bool_env('GRAALPYTEST_ALLOW_NO_JAVA_ASSERTIONS'):
# noinspection PyUnresolvedReferences
if not __graalpython__.java_assert():
if not __graalpython__.java_assert(detailed=True):
sys.exit(
"Java assertions are not enabled, refusing to run. Add --vm.ea to your invocation. Set GRAALPYTEST_ALLOW_NO_JAVA_ASSERTIONS=true to disable this check\n")
"Detailed Java assertions are not enabled, refusing to run. Add --vm.ea --vm.Dpython.DetailedAsserts=true to your invocation. "
"Set GRAALPYTEST_ALLOW_NO_JAVA_ASSERTIONS=true to disable this check.\n")
# noinspection PyUnresolvedReferences
if not hasattr(__graalpython__, 'tdebug'):
sys.exit("Needs to be run with --experimental-options --python.EnableDebuggingBuiltins\n")
Expand Down
1 change: 1 addition & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def wrapper(*args, **kwargs):
[
sys.executable,
"--vm.ea",
"--vm.Dpython.DetailedAsserts=true",
"--experimental-options=true",
"--python.EnableDebuggingBuiltins",
runner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,8 @@ public void setCapiCallTarget(int index, RootCallTarget ct) {
}

public <T extends RootNode> T createCachedRootNode(Function<PythonLanguage, T> rootNodeFunction, Class<? extends Node> key) {
assert RootNode.class.isAssignableFrom(key) || key.getConstructors().length <= 1;
assert RootNode.class.isAssignableFrom(key) || key.getConstructors().length == 0 || key.getConstructors()[0].getParameterCount() == 0;
assert !PythonOptions.detailedAssertionsEnabled() || RootNode.class.isAssignableFrom(key) || key.getConstructors().length <= 1;
assert !PythonOptions.detailedAssertionsEnabled() || RootNode.class.isAssignableFrom(key) || key.getConstructors().length == 0 || key.getConstructors()[0].getParameterCount() == 0;
return createCachedRootNodeUnsafe(rootNodeFunction, key, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ private void initializeTypes() {

private void populateBuiltins() {
sysModule = builtinModules.get(T_SYS);
assert PythonBuiltinClassType.verifySlotsConventions(builtins);
assert !PythonOptions.detailedAssertionsEnabled() || PythonBuiltinClassType.verifySlotsConventions(builtins);
for (PythonBuiltins builtin : builtins) {
builtin.initialize(this);
CoreFunctions annotation = builtin.getClass().getAnnotation(CoreFunctions.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.nodes.object.GetClassNode;
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
Expand Down Expand Up @@ -1261,12 +1262,21 @@ TruffleString doit(VirtualFrame frame,
}
}

@Builtin(name = "java_assert", minNumOfPositionalArgs = 0)
@Builtin(name = "java_assert", minNumOfPositionalArgs = 0, parameterNames = {"detailed"})
@ArgumentClinic(name = "detailed", conversion = ArgumentClinic.ClinicConversion.Boolean, defaultValue = "false")
@GenerateNodeFactory
abstract static class JavaAssertNode extends PythonBuiltinNode {
abstract static class JavaAssertNode extends PythonUnaryClinicBuiltinNode {
@Override
protected ArgumentClinicProvider getArgumentClinic() {
return GraalPythonModuleBuiltinsClinicProviders.JavaAssertNodeClinicProviderGen.INSTANCE;
}

@SuppressWarnings("all")
@Specialization
Object doit() {
boolean doit(boolean detailed) {
if (detailed) {
return PythonOptions.detailedAssertionsEnabled();
}
boolean assertOn = false;
assert assertOn = true;
return assertOn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ private static CApiContext loadCApi(Node node, PythonContext context, TruffleStr
}
CApiTransitions.initializeThreadStateDeallocatingOffsets();

assert PythonCApiAssertions.assertBuiltins(capiLibrary);
assert !PythonOptions.detailedAssertionsEnabled() || PythonCApiAssertions.assertBuiltins(capiLibrary);
cApiContext.pyDateTimeCAPICapsule = PyDateTimeCAPIWrapper.initWrapper(context, cApiContext);

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.nativeaccess.NativeFunctionPointer;
import com.oracle.graal.python.runtime.nativeaccess.NativeMemory;
Expand Down Expand Up @@ -2439,7 +2440,8 @@ public abstract static class ReleaseNativeArgsTupleNode extends Node {
static void doGeneric(long argsTuplePtr, Object[] managedArgs,
@Bind Node inliningTarget) {
assert !HandlePointerConverter.pointsToPyHandleSpace(argsTuplePtr);
assert IsSameTypeNode.executeUncached(GetNativeClassNodeGen.getUncached().execute(null, new PythonAbstractNativeObject(argsTuplePtr)), PythonBuiltinClassType.PTuple);
assert !PythonOptions.detailedAssertionsEnabled() || IsSameTypeNode.executeUncached(GetNativeClassNodeGen.getUncached().execute(null, new PythonAbstractNativeObject(argsTuplePtr)),
PythonBuiltinClassType.PTuple);
long refCount = CApiTransitions.readNativeRefCount(argsTuplePtr);
assert refCount >= 1;
if (refCount > 1) {
Expand All @@ -2451,7 +2453,7 @@ static void doGeneric(long argsTuplePtr, Object[] managedArgs,
return;
}
assert readLongField(argsTuplePtr, CFields.PyVarObject__ob_size) == managedArgs.length;
assert verifyElements(argsTuplePtr, managedArgs);
assert !PythonOptions.detailedAssertionsEnabled() || verifyElements(argsTuplePtr, managedArgs);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(PythonUtils.formatJString("Releasing native args tuple %x.", argsTuplePtr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
import com.oracle.graal.python.builtins.objects.cext.structs.CStructs;
import com.oracle.graal.python.builtins.objects.dict.PDict;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.nativeaccess.NativeMemory;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.CApiState;
Expand Down Expand Up @@ -112,7 +113,8 @@ public static PDict getOrCreateThreadStateDict(PythonContext context, PythonThre

PDict threadStateDict = threadState.getDict();
if (threadStateDict != null) {
assert PythonToNativeInternalNode.executeUncached(threadStateDict, false) == CStructAccess.readPtrField(nativeThreadState, CFields.PyThreadState__dict);
assert !PythonOptions.detailedAssertionsEnabled() || PythonToNativeInternalNode.executeUncached(threadStateDict, false) == CStructAccess.readPtrField(nativeThreadState,
CFields.PyThreadState__dict);
return threadStateDict;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,14 +1144,14 @@ public static IdReference<?> nativeLookupGet(HandleContext context, long pointer
@TruffleBoundary
public static void nativeLookupPut(HandleContext context, long pointer, NativeObjectReference value) {
assert !HandlePointerConverter.pointsToPyHandleSpace(pointer);
assert !context.nativeLookup.containsKey(pointer) || context.nativeLookup.get(pointer).get() == null;
assert !PythonOptions.detailedAssertionsEnabled() || !context.nativeLookup.containsKey(pointer) || context.nativeLookup.get(pointer).get() == null;
context.nativeLookup.put(pointer, value);
}

@TruffleBoundary
public static void nativeLookupPut(HandleContext context, long pointer, PythonObjectReference value) {
assert !HandlePointerConverter.pointsToPyHandleSpace(pointer);
assert !context.nativeLookup.containsKey(pointer) || context.nativeLookup.get(pointer).get() == null;
assert !PythonOptions.detailedAssertionsEnabled() || !context.nativeLookup.containsKey(pointer) || context.nativeLookup.get(pointer).get() == null;
context.nativeLookup.put(pointer, value);
}

Expand All @@ -1164,7 +1164,7 @@ public static IdReference<?> nativeTypeLookupGet(HandleContext context, long poi
assert idx != 0;
assert !HandlePointerConverter.pointsToPyHandleSpace(pointer);
IdReference<?> result = context.nativeTypeLookup[idx];
assert result == nativeLookupGet(context, pointer);
assert !PythonOptions.detailedAssertionsEnabled() || result == nativeLookupGet(context, pointer);
return result;
}

Expand Down Expand Up @@ -1355,12 +1355,14 @@ public static long pointerToStub(long pointer) {
}

public static long pointerToLong(long pointer) {
assert Integer.toHexString((int) ((pointer & ~(HANDLE_TAG_BIT | INTEGER_TAG_BIT)) >> 3)).equals(Long.toHexString(((pointer & ~(HANDLE_TAG_BIT | INTEGER_TAG_BIT)) >> 3)));
assert !PythonOptions.detailedAssertionsEnabled() || Integer.toHexString((int) ((pointer & ~(HANDLE_TAG_BIT | INTEGER_TAG_BIT)) >> 3)).equals(Long.toHexString(((pointer &
~(HANDLE_TAG_BIT | INTEGER_TAG_BIT)) >> 3)));
return (int) (pointer >> 3);
}

public static double pointerToDouble(long pointer) {
assert Integer.toHexString((int) ((pointer & ~(HANDLE_TAG_BIT | FLOAT_TAG_BIT)) >> 3)).equals(Long.toHexString(((pointer & ~(HANDLE_TAG_BIT | FLOAT_TAG_BIT)) >> 3)));
assert !PythonOptions.detailedAssertionsEnabled() || Integer.toHexString((int) ((pointer & ~(HANDLE_TAG_BIT | FLOAT_TAG_BIT)) >> 3)).equals(Long.toHexString(((pointer & ~(HANDLE_TAG_BIT |
FLOAT_TAG_BIT)) >> 3)));
return Float.intBitsToFloat((int) (pointer >> 3));
}
}
Expand Down Expand Up @@ -1961,7 +1963,7 @@ static long doPythonObject(Node inliningTarget, PythonObject pythonObject, boole
pointer = pythonObject.getNativePointer();
}
assert pythonObject.isNative();
assert isGcTrackedIfNecessary(pythonObject);
assert !PythonOptions.detailedAssertionsEnabled() || isGcTrackedIfNecessary(pythonObject);
return pointer;
}

Expand Down Expand Up @@ -2044,7 +2046,7 @@ static long doGeneric(Node inliningTarget, Object obj, boolean needsTransfer,
}
pointer = pythonObject.getNativePointer();
}
assert isGcTrackedIfNecessary(pythonObject);
assert !PythonOptions.detailedAssertionsEnabled() || isGcTrackedIfNecessary(pythonObject);
assert pythonObject.isNative();
return pointer;
}
Expand Down Expand Up @@ -2669,15 +2671,15 @@ private static long addNativeRefCount(long pointer, long refCntDelta, boolean ig

LOGGER.finest(() -> PythonUtils.formatJString("addNativeRefCount %x %x %d + %d", pointer, refCount, refCount, refCntDelta));

assert !isDeallocatingSlowPath(pointer);
assert !PythonOptions.detailedAssertionsEnabled() || !isDeallocatingSlowPath(pointer);
UNSAFE.putLong(pointer + TP_REFCNT_OFFSET, refCount + refCntDelta);
return refCount + refCntDelta;
}

public static long subNativeRefCount(long pointer, long refCntDelta) {
assert PythonContext.get(null).isNativeAccessAllowed();
assert PythonContext.get(null).ownsGil();
assert !isDeallocatingSlowPath(pointer);
assert !PythonOptions.detailedAssertionsEnabled() || !isDeallocatingSlowPath(pointer);
long refCount = UNSAFE.getLong(pointer + TP_REFCNT_OFFSET);
if (refCount == IMMORTAL_REFCNT) {
return IMMORTAL_REFCNT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.oracle.graal.python.builtins.objects.type.TypeFlags;
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinClassProfile;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.nativeaccess.NativeMemory;

public final class GraalPyUnicodeObjectUtil {
Expand Down Expand Up @@ -163,19 +164,20 @@ public static boolean isGraalPyUnicodeObject(long rawPointer) {
boolean isUnicodeSubclass = (readLongField(obType, CFields.PyTypeObject__tp_flags) & TypeFlags.UNICODE_SUBCLASS) != 0L;
assert !HandlePointerConverter.pointsToPyHandleSpace(obType);
// During finalization, the native reference for obType may already have been freed, so it cannot be converted back to a managed class.
assert PythonContext.get(null).isFinalizing() || IsBuiltinClassProfile.profileClassSlowPath(NativeToPythonClassInternalNode.executeUncached(obType),
assert !PythonOptions.detailedAssertionsEnabled() || PythonContext.get(null).isFinalizing() || IsBuiltinClassProfile.profileClassSlowPath(NativeToPythonClassInternalNode.executeUncached(
obType),
PythonBuiltinClassType.PString) == isUnicodeSubclass;
return isUnicodeSubclass;
}

/** Similar to {@code unicodeobject.h:_PyUnicode_NONCOMPACT_DATA} */
public static long getNonCompactDataPointer(long rawPointer) {
assert isGraalPyUnicodeObject(rawPointer) && !isCompact(rawPointer);
assert !PythonOptions.detailedAssertionsEnabled() || isGraalPyUnicodeObject(rawPointer) && !isCompact(rawPointer);
return readPtrField(rawPointer, CFields.GraalPyUnicodeObject__data);
}

public static long getUtf8DataPointer(long rawPointer) {
assert isGraalPyUnicodeObject(rawPointer);
assert !PythonOptions.detailedAssertionsEnabled() || isGraalPyUnicodeObject(rawPointer);
return readPtrField(rawPointer, CFields.GraalPyUnicodeObject__utf8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.oracle.graal.python.nodes.PGuards;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromPythonObjectNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.dsl.Bind;
Expand Down Expand Up @@ -132,7 +133,7 @@ public abstract static class LengthNode extends Node {

@Specialization(guards = "self.cachedLength >= 0")
static int cachedLength(DynamicObjectStorage self) {
assert self.cachedLength == actualLength(self) : "stale DynamicObjectStorage length";
assert !PythonOptions.detailedAssertionsEnabled() || self.cachedLength == actualLength(self) : "stale DynamicObjectStorage length";
return self.cachedLength;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.oracle.graal.python.nodes.util.CannotCastException;
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.util.PythonUtils;
Expand Down Expand Up @@ -150,7 +151,7 @@ public Object getContext() {
}

public void setContext(Object context) {
assert context == null || PyExceptionInstanceCheckNode.executeUncached(context);
assert !PythonOptions.detailedAssertionsEnabled() || context == null || PyExceptionInstanceCheckNode.executeUncached(context);
this.context = context;
}

Expand All @@ -159,7 +160,7 @@ public Object getCause() {
}

public void setCause(Object cause) {
assert cause == null || PyExceptionInstanceCheckNode.executeUncached(cause);
assert !PythonOptions.detailedAssertionsEnabled() || cause == null || PyExceptionInstanceCheckNode.executeUncached(cause);
this.cause = cause;
this.suppressContext = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
import com.oracle.graal.python.runtime.ExecutionContext.BoundaryCallContext;
import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PythonErrorType;
import com.oracle.graal.python.runtime.formatting.FloatFormatter;
import com.oracle.graal.python.runtime.formatting.IntegerFormatter;
Expand Down Expand Up @@ -217,7 +218,7 @@ static Object doGeneric(VirtualFrame frame, Object cls, Object x, Object baseObj
if (isPrimitiveIntProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.PInt)) {
return result;
} else {
assert IsSubtypeNode.getUncached().execute(cls, PythonBuiltinClassType.PInt);
assert !PythonOptions.detailedAssertionsEnabled() || IsSubtypeNode.getUncached().execute(cls, PythonBuiltinClassType.PInt);
PInt managedInt = createIntSubclassNode.execute(inliningTarget, cls, result, getInstanceShape.execute(cls));
if (needsNativeAllocationNode.execute(inliningTarget, cls)) {
// needsNativeAllocationNode acts as branch profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ public void setDict(Node inliningTarget, HiddenAttr.WriteNode writeNode, PDict d
writeNode.execute(inliningTarget, this, HiddenAttr.DICT, dict);
}

/**
* For use in assertions only. The uncached dictionary lookup requires detailed assertions.
*/
public boolean checkDictFlags() {
return checkDictFlags(GetDictIfExistsNode.getDictUncached(this));
return !PythonOptions.detailedAssertionsEnabled() || checkDictFlags(GetDictIfExistsNode.getDictUncached(this));
}

/**
* For use in assertions only, when the dictionary is already known.
*/
public boolean checkDictFlags(PDict dict) {
assert dict == null || hasShapeFlag(HAS_DICT);
assert (dict == null || dict.getDictStorage() instanceof DynamicObjectStorage domStorage && domStorage.getStore() == this) || hasShapeFlag(HAS_MATERIALIZED_DICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static TruffleString doMaterialized(PString x, @SuppressWarnings("unused") boole
static TruffleString doNative(PString x, boolean copyNativeData,
@Cached TruffleString.FromNativePointerWithCompactionUTF32Node fromNativePointerNode) {
assert x.isNative();
assert PythonToNativeInternalNode.executeUncached(x, false) == x.getNativePointer();
assert !PythonOptions.detailedAssertionsEnabled() || PythonToNativeInternalNode.executeUncached(x, false) == x.getNativePointer();
long ptr = HandlePointerConverter.pointerToStub(x.getNativePointer());
long data = CStructAccess.readPtrField(ptr, CFields.GraalPyUnicodeObject__data);
assert data != 0;
Expand Down
Loading
Loading