[Vm-dev] [commit][3735] CogVm source as per VMMaker.oscog-eem.1878

commits at squeakvm.org commits at squeakvm.org
Thu Jun 2 01:01:02 UTC 2016


Revision: 3735
Author:   eliot
Date:     2016-06-01 18:00:59 -0700 (Wed, 01 Jun 2016)
Log Message:
-----------
CogVm source as per VMMaker.oscog-eem.1878

Check for allocation failure in the LargeIntegersPlugin and fail primitives
when space runs out. Stops (2 raisedTo: 100000000) basicSize crashing system.

This fix is clearly unsatisfactory;. the ciode fails to slow Smalltalk code.
We'd like to run the GC but Spur's style is not to GC in primitives.  If we
change the plugin to do GC in primtiives we lose the speed advantage of the
no-GC style of code.  One approach might be to estimate the memory needed as
early as possible, and run a GC if not enough memory is available for the
result, recomputing base pointers if GC is run.  This would avoid the awful
remapOop:in: style whioch is pessimistic; it puts things in a stack and takes
them back out whether a GC is needed or not.  We should use an optimistic
algorithm; especially for something as performance sensitive as large integer
arithmetic.

Modified Paths:
--------------
    branches/Cog/src/plugins/LargeIntegers/LargeIntegers.c

Property Changed:
----------------
    branches/Cog/platforms/Cross/vm/sqSCCSVersion.h


Property changes on: branches/Cog/platforms/Cross/vm/sqSCCSVersion.h
___________________________________________________________________
Modified: checkindate
   - Wed Jun  1 16:52:50 PDT 2016
   + Wed Jun  1 17:58:41 PDT 2016

Modified: branches/Cog/src/plugins/LargeIntegers/LargeIntegers.c
===================================================================
--- branches/Cog/src/plugins/LargeIntegers/LargeIntegers.c	2016-06-01 23:55:01 UTC (rev 3734)
+++ branches/Cog/src/plugins/LargeIntegers/LargeIntegers.c	2016-06-02 01:00:59 UTC (rev 3735)
@@ -1,9 +1,9 @@
 /* Automatically generated by
-	SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.1876 uuid: 28e91d90-4197-436d-9702-7c7dae02e85e
+	SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.1878 uuid: 71f5bdb3-74c3-4a8c-bbb9-c78c327e4823
    from
-	LargeIntegersPlugin VMMaker.oscog-eem.1876 uuid: 28e91d90-4197-436d-9702-7c7dae02e85e
+	LargeIntegersPlugin VMMaker.oscog-eem.1878 uuid: 71f5bdb3-74c3-4a8c-bbb9-c78c327e4823
  */
-static char __buildInfo[] = "LargeIntegersPlugin VMMaker.oscog-eem.1876 uuid: 28e91d90-4197-436d-9702-7c7dae02e85e " __DATE__ ;
+static char __buildInfo[] = "LargeIntegersPlugin VMMaker.oscog-eem.1878 uuid: 71f5bdb3-74c3-4a8c-bbb9-c78c327e4823 " __DATE__ ;
 
 
 
@@ -32,6 +32,10 @@
 #include "sqMemoryAccess.h"
 
 
+/*** Constants ***/
+#define PrimErrNoMemory 9
+
+
 /*** Function Prototypes ***/
 static sqInt anyBitOfLargeIntfromto(sqInt anOop, sqInt start, sqInt stopArg);
 static sqInt byteSizeOfCSI(sqInt csi);
@@ -145,6 +149,7 @@
 static sqInt (*popRemappableOop)(void);
 static usqInt (*positive32BitValueOf)(sqInt oop);
 static sqInt (*primitiveFail)(void);
+static sqInt (*primitiveFailFor)(sqInt reasonCode);
 static sqInt (*pushRemappableOop)(sqInt oop);
 static sqInt (*slotSizeOf)(sqInt oop);
 static sqInt (*stObjectatput)(sqInt array, sqInt index, sqInt value);
@@ -172,6 +177,7 @@
 extern sqInt popRemappableOop(void);
 extern usqInt positive32BitValueOf(sqInt oop);
 extern sqInt primitiveFail(void);
+extern sqInt primitiveFailFor(sqInt reasonCode);
 extern sqInt pushRemappableOop(sqInt oop);
 extern sqInt slotSizeOf(sqInt oop);
 extern sqInt stObjectatput(sqInt array, sqInt index, sqInt value);
@@ -184,9 +190,9 @@
 struct VirtualMachine* interpreterProxy;
 static const char *moduleName =
 #ifdef SQUEAK_BUILTIN_PLUGIN
-	"LargeIntegers v2.0 VMMaker.oscog-eem.1876 (i)"
+	"LargeIntegers v2.0 VMMaker.oscog-eem.1878 (i)"
 #else
-	"LargeIntegers v2.0 VMMaker.oscog-eem.1876 (e)"
+	"LargeIntegers v2.0 VMMaker.oscog-eem.1878 (e)"
 #endif
 ;
 static const int  orOpIndex = 1;
@@ -556,7 +562,7 @@
 	sqInt i;
 	sqInt i1;
 	sqInt limit;
-	sqInt rshift;
+	int rshift;
 
 	digitShift = shiftCount / 32;
 	bitShift = shiftCount % 32;
@@ -795,7 +801,7 @@
 	sqInt digitShift;
 	sqInt i;
 	sqInt j;
-	sqInt leftShift;
+	int leftShift;
 	sqInt limit;
 	sqInt start;
 
@@ -988,9 +994,9 @@
 	digitSize = (byteSize + 3) / 4;
 	for (ix = 1; ix <= digitSize; ix += 1) {
 		/* begin cDigitOf:at:put: */
-		aValue = ((unsigned int) (((usqInt) ((val < 0
-	? 0 - val
-	: val))) >> ((ix - 1) * 32)));
+		aValue = ((usqInt) ((val < 0
+			? 0 - val
+			: val))) >> ((ix - 1) * 32);
 		pDigit[ix - 1] = (SQ_SWAP_4_BYTES_IF_BIGENDIAN(aValue));
 	}
 	return res;
@@ -1072,6 +1078,9 @@
 	shortInt = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(sum)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	/* begin cDigitAdd:len:with:len:into: */
 	pWordShort = ((unsigned int *) (((unsigned int *) (firstIndexableField(shortInt)))));
 	pWordLong = ((unsigned int *) (((unsigned int *) (firstIndexableField(longInt)))));
@@ -1103,6 +1112,9 @@
 		sum = popRemappableOop()
 #endif /* SPURVM */
 ;
+		if (!(newSum)) {
+			return primitiveFailFor(PrimErrNoMemory);
+		}
 		/* begin cDigitCopyFrom:to:len: */
 		pFrom = ((unsigned int *) (((unsigned int *) (firstIndexableField(sum)))));
 		pTo = ((unsigned int *) (((unsigned int *) (firstIndexableField(newSum)))));
@@ -1215,6 +1227,9 @@
 	shortLarge = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(result)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	/* begin cDigitOp:short:len:long:len:into: */
 	pWordShort = ((unsigned int *) (((unsigned int *) (firstIndexableField(shortLarge)))));
 	pWordLong = ((unsigned int *) (((unsigned int *) (firstIndexableField(longLarge)))));
@@ -1293,7 +1308,7 @@
 	unsigned long long a;
 	unsigned long long b;
 	int cond;
-	sqInt d;
+	int d;
 	unsigned int dh;
 	sqInt div;
 	sqInt divLen;
@@ -1564,6 +1579,9 @@
 	firstLarge = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(prod)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	/* begin cDigitMontgomery:len:times:len:modulo:len:mInvModB:into: */
 	pFirst = ((unsigned int *) (((unsigned int *) (firstIndexableField(firstLarge)))));
 	pSecond = ((unsigned int *) (((unsigned int *) (firstIndexableField(secondLarge)))));
@@ -1683,6 +1701,9 @@
 	shortInt = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(prod)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	/* begin cDigitMultiply:len:with:len:into:len: */
 	pWordShort = ((unsigned int *) (((unsigned int *) (firstIndexableField(shortInt)))));
 	pWordLong = ((unsigned int *) (((unsigned int *) (firstIndexableField(longInt)))));
@@ -1793,7 +1814,7 @@
 	sqInt i;
 	sqInt largeDigitLen;
 	sqInt larger;
-	sqInt neg;
+	int neg;
 	unsigned int *pWordLarge;
 	unsigned int *pWordRes;
 	unsigned int *pWordSmall;
@@ -1847,6 +1868,9 @@
 	smaller = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(res)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	/* begin cDigitSub:len:with:len:into: */
 	pWordSmall = ((unsigned int *) (((unsigned int *) (firstIndexableField(smaller)))));
 	pWordLarge = ((unsigned int *) (((unsigned int *) (firstIndexableField(larger)))));
@@ -1891,7 +1915,7 @@
 	sqInt oldDigitLen;
 	unsigned int *pFrom;
 	unsigned int *pTo;
-	sqInt rshift;
+	int rshift;
 
 	oldDigitLen = ((slotSizeOf(anOop)) + 3) / 4;
 	if (((highBit = cDigitHighBitlen(((unsigned int *) (firstIndexableField(anOop))), oldDigitLen))) == 0) {
@@ -1908,6 +1932,9 @@
 	anOop = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(newOop)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	newDigitLen = (newByteLen + 3) / 4;
 	/* begin cDigitLshift:from:len:to:len: */
 	pFrom = ((unsigned int *) (((unsigned int *) (firstIndexableField(anOop)))));
@@ -1964,7 +1991,7 @@
 	sqInt i;
 	sqInt j;
 	unsigned int lastDigit;
-	sqInt leftShift;
+	int leftShift;
 	sqInt limit;
 	sqInt newBitLen;
 	sqInt newByteLen;
@@ -2008,6 +2035,9 @@
 	anOop = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(newOop)) {
+		return primitiveFailFor(PrimErrNoMemory);
+	}
 	/* begin cDigitRshift:from:len:to:len: */
 	pFrom = ((unsigned int *) (((unsigned int *) (firstIndexableField(anOop)))));
 	pTo = ((unsigned int *) (((unsigned int *) (firstIndexableField(newOop)))));
@@ -2432,6 +2462,10 @@
 	shortInt = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(sum)) {
+		_return_value = primitiveFailFor(PrimErrNoMemory);
+		goto l4;
+	}
 	/* begin cDigitAdd:len:with:len:into: */
 	pWordShort = ((unsigned int *) (((unsigned int *) (firstIndexableField(shortInt)))));
 	pWordLong = ((unsigned int *) (((unsigned int *) (firstIndexableField(longInt)))));
@@ -2463,6 +2497,10 @@
 		sum = popRemappableOop()
 #endif /* SPURVM */
 ;
+		if (!(newSum)) {
+			_return_value = primitiveFailFor(PrimErrNoMemory);
+			goto l4;
+		}
 		/* begin cDigitCopyFrom:to:len: */
 		pFrom = ((unsigned int *) (((unsigned int *) (firstIndexableField(sum)))));
 		pTo = ((unsigned int *) (((unsigned int *) (firstIndexableField(newSum)))));
@@ -2482,6 +2520,7 @@
 			: normalizePositive(sum));
 	}
 	_return_value = sum;
+l4:	/* end digitAddLarge:with: */;
 	if (failed()) {
 		return null;
 	}
@@ -2558,7 +2597,7 @@
 	sqInt aLarge;
 	sqInt aLargeInteger;
 	sqInt anInteger;
-	sqInt rShift;
+	int rShift;
 	sqInt shiftCount;
 	sqInt _return_value;
 
@@ -2778,7 +2817,7 @@
 	unsigned long long a;
 	unsigned long long b;
 	int cond;
-	sqInt d;
+	int d;
 	unsigned int dh;
 	sqInt div;
 	sqInt divLen;
@@ -3189,6 +3228,10 @@
 	shortInt = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(prod)) {
+		_return_value = primitiveFailFor(PrimErrNoMemory);
+		goto l2;
+	}
 	/* begin cDigitMultiply:len:with:len:into:len: */
 	pWordShort = ((unsigned int *) (((unsigned int *) (firstIndexableField(shortInt)))));
 	pWordLong = ((unsigned int *) (((unsigned int *) (firstIndexableField(longInt)))));
@@ -3226,6 +3269,7 @@
 	_return_value = (neg
 		? normalizeNegative(prod)
 		: normalizePositive(prod));
+l2:	/* end digitMultiplyLarge:with:negative: */;
 	if (failed()) {
 		return null;
 	}
@@ -3244,7 +3288,7 @@
 	sqInt i;
 	sqInt largeDigitLen;
 	sqInt larger;
-	sqInt neg;
+	int neg;
 	unsigned int *pWordLarge;
 	unsigned int *pWordRes;
 	unsigned int *pWordSmall;
@@ -3347,6 +3391,10 @@
 	smaller = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(res)) {
+		_return_value = primitiveFailFor(PrimErrNoMemory);
+		goto l2;
+	}
 	/* begin cDigitSub:len:with:len:into: */
 	pWordSmall = ((unsigned int *) (((unsigned int *) (firstIndexableField(smaller)))));
 	pWordLarge = ((unsigned int *) (((unsigned int *) (firstIndexableField(larger)))));
@@ -3365,6 +3413,7 @@
 	_return_value = (neg
 		? normalizeNegative(res)
 		: normalizePositive(res));
+l2:	/* end digitSubLarge:with: */;
 	if (failed()) {
 		return null;
 	}
@@ -3539,6 +3588,10 @@
 	firstLarge = popRemappableOop()
 #endif /* SPURVM */
 ;
+	if (!(prod)) {
+		_return_value = primitiveFailFor(PrimErrNoMemory);
+		goto l2;
+	}
 	/* begin cDigitMontgomery:len:times:len:modulo:len:mInvModB:into: */
 	pFirst = ((unsigned int *) (((unsigned int *) (firstIndexableField(firstLarge)))));
 	pSecond = ((unsigned int *) (((unsigned int *) (firstIndexableField(secondLarge)))));
@@ -3688,6 +3741,7 @@
 		popRemappableOop = interpreterProxy->popRemappableOop;
 		positive32BitValueOf = interpreterProxy->positive32BitValueOf;
 		primitiveFail = interpreterProxy->primitiveFail;
+		primitiveFailFor = interpreterProxy->primitiveFailFor;
 		pushRemappableOop = interpreterProxy->pushRemappableOop;
 		slotSizeOf = interpreterProxy->slotSizeOf;
 		stObjectatput = interpreterProxy->stObjectatput;



More information about the Vm-dev mailing list