[Vm-dev] [commit][3377] CogVM source as per VMMaker.oscog-eem.1361

commits at squeakvm.org commits at squeakvm.org
Wed Jun 17 03:42:21 UTC 2015


Revision: 3377
Author:   eliot
Date:     2015-06-16 20:42:19 -0700 (Tue, 16 Jun 2015)
Log Message:
-----------
CogVM source as per VMMaker.oscog-eem.1361

Cogit:
Fix return type calculation for mapEntrySize (handle
unsigned char + unsigned long).  Fixes compilation of cogitIA32.c.

Sista Cogit:
Fix a warning in picDataFor:Annotation:Mcpc:Bcpc:Method:

ARM Cogit:
Fix growing literals.  Can't use realloc cuz existing
refs must be updated to new literals.

Fix literalInstructionInRange: in C by making sure
that literalOpcodeIndex is signed.

Fix type errors and typos.

ARM Cogit:
Provide the rest of the literal scanning and update support required for
out-of-line literals.

Fix Slang translation.

Revise object reference scanning in PICs to allow for out-of-line literals.  Indirect through the literals manager to access obj refs and distinguish method literal and class obj refs. Rename the accessors to make clear they're for use only in closed PICs.

Fix otherwise clause of inverseOpcodeFor:.

Declare OutOfLineLiteralsManager' literals correctly.

Slang:
Modify typedef printing so that all class names from the concrete type through
to the abstract type are renamed with a define if necessary.  Hence fix
compilation of cogitARMv5.c.  (Still have CogOutOfLineLiteralsARMCompiler
methods to implement to get it to link though).

Fix the extern extern regression on generating plugins
caused by the changes in VMMaker.oscog-eem.1349

Fix Slang for sends that return the result of a message send of a method
containing value expansions.  The old code would return the value of the
first statement of each block expanded in a value expansion, instead of
the last. Fixes CogARMCompiler>>computeMinimumSize.

Modified Paths:
--------------
    branches/Cog/nsspursrc/plugins/BitBltPlugin/BitBltPlugin.c
    branches/Cog/nsspursrc/plugins/FilePlugin/FilePlugin.c
    branches/Cog/nsspursrc/vm/cogit.h
    branches/Cog/nsspursrc/vm/cogitARMv5.c
    branches/Cog/nsspursrc/vm/cogitIA32.c
    branches/Cog/nsspursrc/vm/cointerp.c
    branches/Cog/nsspursrc/vm/cointerp.h
    branches/Cog/nsspursrc/vm/gcc3x-cointerp.c
    branches/Cog/nsspurstack64src/vm/gcc3x-interp.c
    branches/Cog/nsspurstack64src/vm/interp.c
    branches/Cog/nsspurstacksrc/vm/gcc3x-interp.c
    branches/Cog/nsspurstacksrc/vm/interp.c
    branches/Cog/spursistasrc/vm/cogit.h
    branches/Cog/spursistasrc/vm/cogitARMv5.c
    branches/Cog/spursistasrc/vm/cogitIA32.c
    branches/Cog/spursistasrc/vm/cointerp.c
    branches/Cog/spursistasrc/vm/cointerp.h
    branches/Cog/spursistasrc/vm/gcc3x-cointerp.c
    branches/Cog/spursrc/vm/cogit.h
    branches/Cog/spursrc/vm/cogitARMv5.c
    branches/Cog/spursrc/vm/cogitIA32.c
    branches/Cog/spursrc/vm/cointerp.c
    branches/Cog/spursrc/vm/cointerp.h
    branches/Cog/spursrc/vm/gcc3x-cointerp.c
    branches/Cog/spurstack64src/vm/gcc3x-interp.c
    branches/Cog/spurstack64src/vm/interp.c
    branches/Cog/spurstacksrc/vm/gcc3x-interp.c
    branches/Cog/spurstacksrc/vm/interp.c
    branches/Cog/src/plugins/BitBltPlugin/BitBltPlugin.c
    branches/Cog/src/plugins/FilePlugin/FilePlugin.c
    branches/Cog/src/plugins/SqueakFFIPrims/ARM32FFIPlugin.c
    branches/Cog/src/vm/cogit.h
    branches/Cog/src/vm/cogitARMv5.c
    branches/Cog/src/vm/cogitIA32.c
    branches/Cog/src/vm/cointerp.c
    branches/Cog/src/vm/cointerp.h
    branches/Cog/src/vm/cointerpmt.c
    branches/Cog/src/vm/cointerpmt.h
    branches/Cog/src/vm/gcc3x-cointerp.c
    branches/Cog/src/vm/gcc3x-cointerpmt.c
    branches/Cog/stacksrc/vm/gcc3x-interp.c
    branches/Cog/stacksrc/vm/interp.c

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

Modified: branches/Cog/nsspursrc/plugins/BitBltPlugin/BitBltPlugin.c
===================================================================
--- branches/Cog/nsspursrc/plugins/BitBltPlugin/BitBltPlugin.c	2015-06-16 02:42:34 UTC (rev 3376)
+++ branches/Cog/nsspursrc/plugins/BitBltPlugin/BitBltPlugin.c	2015-06-17 03:42:19 UTC (rev 3377)
@@ -1,9 +1,9 @@
 /* Automatically generated by
-	SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.1325 uuid: a0bb0f7f-5e6e-48a7-bf73-fa5d135e06c0
+	SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.1359 uuid: 0e62a222-6136-430f-9bc2-8e7cee245076
    from
-	BitBltSimulation VMMaker.oscog-eem.1325 uuid: a0bb0f7f-5e6e-48a7-bf73-fa5d135e06c0
+	BitBltSimulation VMMaker.oscog-eem.1359 uuid: 0e62a222-6136-430f-9bc2-8e7cee245076
  */
-static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.1325 uuid: a0bb0f7f-5e6e-48a7-bf73-fa5d135e06c0 " __DATE__ ;
+static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.1359 uuid: 0e62a222-6136-430f-9bc2-8e7cee245076 " __DATE__ ;
 
 
 
@@ -111,7 +111,7 @@
 EXPORT(sqInt) copyBitsFromtoat(sqInt startX, sqInt stopX, sqInt yValue);
 static sqInt copyBitsLockedAndClipped(void);
 static sqInt copyBitsRule41Test(void);
-void copyBitsFallback(operation_t *op, unsigned int flags);
+extern void copyBitsFallback(operation_t *op, unsigned int flags);
 static sqInt copyLoop(void);
 static sqInt copyLoopNoSource(void);
 static sqInt copyLoopPixMap(void);
@@ -344,9 +344,9 @@
 };
 static const char *moduleName =
 #ifdef SQUEAK_BUILTIN_PLUGIN
-	"BitBltPlugin VMMaker.oscog-eem.1325 (i)"
+	"BitBltPlugin VMMaker.oscog-eem.1359 (i)"
 #else
-	"BitBltPlugin VMMaker.oscog-eem.1325 (e)"
+	"BitBltPlugin VMMaker.oscog-eem.1359 (e)"
 #endif
 ;
 static sqInt noHalftone;

Modified: branches/Cog/nsspursrc/plugins/FilePlugin/FilePlugin.c
===================================================================
--- branches/Cog/nsspursrc/plugins/FilePlugin/FilePlugin.c	2015-06-16 02:42:34 UTC (rev 3376)
+++ branches/Cog/nsspursrc/plugins/FilePlugin/FilePlugin.c	2015-06-17 03:42:19 UTC (rev 3377)
@@ -1,9 +1,9 @@
 /* Automatically generated by
-	VMPluginCodeGenerator VMMaker.oscog-eem.1325 uuid: a0bb0f7f-5e6e-48a7-bf73-fa5d135e06c0
+	VMPluginCodeGenerator VMMaker.oscog-eem.1359 uuid: 0e62a222-6136-430f-9bc2-8e7cee245076
    from
-	FilePlugin VMMaker.oscog-eem.1325 uuid: a0bb0f7f-5e6e-48a7-bf73-fa5d135e06c0
+	FilePlugin VMMaker.oscog-eem.1359 uuid: 0e62a222-6136-430f-9bc2-8e7cee245076
  */
-static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.1325 uuid: a0bb0f7f-5e6e-48a7-bf73-fa5d135e06c0 " __DATE__ ;
+static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.1359 uuid: 0e62a222-6136-430f-9bc2-8e7cee245076 " __DATE__ ;
 
 
 
@@ -53,8 +53,8 @@
 /*** Function Prototypes ***/
 static sqInt asciiDirectoryDelimiter(void);
 EXPORT(sqInt) fileOpenNamesizewritesecure(char *nameIndex, sqInt nameSize, sqInt writeFlag, sqInt secureFlag);
-sqInt fileRecordSize(void);
-SQFile * fileValueOf(sqInt objectPointer);
+extern sqInt fileRecordSize(void);
+extern SQFile * fileValueOf(sqInt objectPointer);
 EXPORT(const char*) getModuleName(void);
 EXPORT(sqInt) getThisSession(void);
 EXPORT(sqInt) initialiseModule(void);
@@ -178,9 +178,9 @@
 struct VirtualMachine* interpreterProxy;
 static const char *moduleName =
 #ifdef SQUEAK_BUILTIN_PLUGIN
-	"FilePlugin VMMaker.oscog-eem.1325 (i)"
+	"FilePlugin VMMaker.oscog-eem.1359 (i)"
 #else
-	"FilePlugin VMMaker.oscog-eem.1325 (e)"
+	"FilePlugin VMMaker.oscog-eem.1359 (e)"
 #endif
 ;
 static void * sCCPfn;

Modified: branches/Cog/nsspursrc/vm/cogit.h
===================================================================
--- branches/Cog/nsspursrc/vm/cogit.h	2015-06-16 02:42:34 UTC (rev 3376)
+++ branches/Cog/nsspursrc/vm/cogit.h	2015-06-17 03:42:19 UTC (rev 3377)
@@ -1,5 +1,5 @@
 /* Automatically generated by
-	CCodeGenerator VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6
+	CCodeGenerator VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928
  */
 
 

Modified: branches/Cog/nsspursrc/vm/cogitARMv5.c
===================================================================
--- branches/Cog/nsspursrc/vm/cogitARMv5.c	2015-06-16 02:42:34 UTC (rev 3376)
+++ branches/Cog/nsspursrc/vm/cogitARMv5.c	2015-06-17 03:42:19 UTC (rev 3377)
@@ -1,9 +1,9 @@
 /* Automatically generated by
-	CCodeGenerator VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6
+	CCodeGenerator VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928
    from
-	StackToRegisterMappingCogit VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6
+	StackToRegisterMappingCogit VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928
  */
-static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6 " __DATE__ ;
+static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928 " __DATE__ ;
 char *__cogitBuildInfo = __buildInfo;
 
 
@@ -34,6 +34,8 @@
  } AbstractInstruction;
 
 #define CogOutOfLineLiteralsARMCompiler AbstractInstruction
+#define CogARMCompiler AbstractInstruction
+#define CogAbstractInstruction AbstractInstruction
 
 
 typedef struct {
@@ -89,6 +91,7 @@
  } BytecodeFixup;
 
 #define CogSSBytecodeFixup BytecodeFixup
+#define CogBytecodeFixup BytecodeFixup
 
 
 typedef struct {
@@ -405,7 +408,7 @@
 static sqInt isJump(AbstractInstruction * self_in_isJump) NoDbgRegParms;
 static sqInt isLongJump(AbstractInstruction * self_in_isLongJump) NoDbgRegParms;
 static AbstractInstruction * jmpTarget(AbstractInstruction * self_in_jmpTarget, AbstractInstruction *anAbstractInstruction) NoDbgRegParms;
-static unsigned long labelOffset(AbstractInstruction * self_in_labelOffset) NoDbgRegParms;
+static usqInt labelOffset(AbstractInstruction * self_in_labelOffset) NoDbgRegParms;
 static sqInt numCheckFeaturesOpcodes(AbstractInstruction * self_in_numCheckFeaturesOpcodes) NoDbgRegParms;
 static AbstractInstruction * relocateJumpLongBeforeFollowingAddressby(AbstractInstruction * self_in_relocateJumpLongBeforeFollowingAddressby, sqInt pc, sqInt delta) NoDbgRegParms;
 static AbstractInstruction * resolveJumpTarget(AbstractInstruction * self_in_resolveJumpTarget) NoDbgRegParms;
@@ -569,7 +572,7 @@
 static sqInt checkIfValidOopRefAndTargetpccogMethod(sqInt annotation, char *mcpc, sqInt cogMethod) NoDbgRegParms;
 static sqInt checkIfValidOopRefpccogMethod(sqInt annotation, char *mcpc, sqInt cogMethod) NoDbgRegParms;
 extern sqInt checkIntegrityOfObjectReferencesInCode(sqInt gcModes);
-static sqInt checkMaybeObjRefAt(sqInt mcpc) NoDbgRegParms;
+static sqInt checkMaybeObjRefInClosedPIC(sqInt maybeObject) NoDbgRegParms;
 static sqInt checkValidObjectReferencesInClosedPIC(CogMethod *cPIC) NoDbgRegParms;
 static sqInt closedPICRefersToUnmarkedObject(CogMethod *cPIC) NoDbgRegParms;
 extern char * codeEntryFor(char *address);
@@ -615,7 +618,7 @@
 static sqInt findIsBackwardBranchMcpcBcpcMatchingMcpc(BytecodeDescriptor *descriptor, sqInt isBackwardBranch, char *mcpc, sqInt bcpc, void *targetMcpc) NoDbgRegParms;
 extern void followForwardedLiteralsIn(CogMethod *cogMethod);
 extern void followForwardedMethods(void);
-static sqInt followMaybeObjRefAt(sqInt mcpc) NoDbgRegParms;
+static sqInt followMaybeObjRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static sqInt followMethodReferencesInClosedPIC(CogMethod *cPIC) NoDbgRegParms;
 static void freePICsWithFreedTargets(void);
 extern void freeUnmarkedMachineCode(void);
@@ -761,7 +764,8 @@
 extern void unlinkSendsOfisMNUSelector(sqInt selector, sqInt isMNUSelector);
 extern void unlinkSendsToFree(void);
 extern void unlinkSendsToandFreeIf(sqInt targetMethodObject, sqInt freeIfTrue);
-static sqInt updateMaybeObjRefAt(sqInt mcpc) NoDbgRegParms;
+static sqInt updateMaybeClassRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
+static sqInt updateMaybeObjRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static AbstractInstruction * gXorCwR(sqInt wordConstant, sqInt reg) NoDbgRegParms;
 static void zeroOpcodeIndex(void);
 extern void addAllToYoungReferrers(void);
@@ -903,8 +907,10 @@
 static sqInt literalLoadInstructionBytes(AbstractInstruction * self_in_literalLoadInstructionBytes) NoDbgRegParms;
 static sqInt outOfLineLiteralOpcodeLimit(AbstractInstruction * self_in_outOfLineLiteralOpcodeLimit) NoDbgRegParms;
 static sqInt pcRelativeAddressAt(AbstractInstruction * self_in_pcRelativeAddressAt, sqInt instrAddress) NoDbgRegParms;
+static AbstractInstruction * relocateMethodReferenceBeforeAddressby(AbstractInstruction * self_in_relocateMethodReferenceBeforeAddressby, sqInt pc, sqInt delta) NoDbgRegParms;
 static sqInt rewriteFullTransferAttargetexpectedInstruction(AbstractInstruction * self_in_rewriteFullTransferAttargetexpectedInstruction, usqInt callSiteReturnAddress, usqInt callTargetAddress, sqInt expectedInstruction) NoDbgRegParms;
 static sqInt rewriteInlineCacheAttagtarget(AbstractInstruction * self_in_rewriteInlineCacheAttagtarget, usqInt callSiteReturnAddress, sqInt cacheTag, usqInt callTargetAddress) NoDbgRegParms;
+static AbstractInstruction * rewriteInlineCacheTagat(AbstractInstruction * self_in_rewriteInlineCacheTagat, sqInt cacheTag, sqInt callSiteReturnAddress) NoDbgRegParms;
 static usqInt sizePCDependentInstructionAt(AbstractInstruction * self_in_sizePCDependentInstructionAt, sqInt eventualAbsoluteAddress) NoDbgRegParms;
 static AbstractInstruction * storeLiteralbeforeFollowingAddress(AbstractInstruction * self_in_storeLiteralbeforeFollowingAddress, sqInt literal, sqInt followingAddress) NoDbgRegParms;
 static AbstractInstruction * updateLabel(AbstractInstruction * self_in_updateLabel, AbstractInstruction *labelInstruction) NoDbgRegParms;
@@ -918,10 +924,12 @@
 static AbstractInstruction * allocateLiteral(sqInt aLiteral) NoDbgRegParms;
 static AbstractInstruction * checkLiteralforInstruction(sqInt literal, AbstractInstruction *anInstruction) NoDbgRegParms;
 static AbstractInstruction * checkQuickConstantforInstruction(sqInt literal, AbstractInstruction *anInstruction) NoDbgRegParms;
+static sqInt classRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static sqInt dumpLiterals(sqInt generateBranchAround) NoDbgRegParms;
-static sqInt literalInstructionInRange(sqInt litInst) NoDbgRegParms;
+static sqInt literalInstructionInRange(AbstractInstruction *litInst) NoDbgRegParms;
 static AbstractInstruction * locateLiteral(sqInt aLiteral) NoDbgRegParms;
 static sqInt mustDumpLiterals(sqInt currentOpcodeIndex) NoDbgRegParms;
+static sqInt objRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static sqInt resetForBlockCompile(void);
 static sqInt saveForBlockCompile(void);
 static sqInt compileBlockDispatch(void);
@@ -1807,7 +1815,7 @@
 static sqInt lastDumpedLiteralIndex;
 static sqInt lastSend;
 static usqInt limitAddress;
-static sqInt literals;
+static AbstractInstruction * literals;
 static sqInt literalsSize;
 static sqInt maxLitIndex;
 static sqInt methodAbortTrampolines[4];
@@ -1827,7 +1835,7 @@
 static sqInt numAbstractOpcodes;
 static sqInt numIRCs;
 static sqInt numPICCases;
-static sqInt objectReferencesInRuntime[NumObjRefsInRuntime];
+static usqInt objectReferencesInRuntime[NumObjRefsInRuntime];
 static sqInt opcodeIndex;
 static CogMethod *openPICList = 0;
 static sqInt openPICSize;
@@ -2090,7 +2098,7 @@
 	compileBlockFrameBuild: */
 
 	/* CogAbstractInstruction>>#labelOffset */
-static unsigned long
+static usqInt
 labelOffset(AbstractInstruction * self_in_labelOffset)
 {
 	return ((self_in_labelOffset->operands))[1];
@@ -2481,16 +2489,12 @@
 		value = constant;
 		while (1) {
 			if ((value & 0xFF) == value) {
-				return n = constant != value;
-				4;
+				return 4;
 
 			}
 			for (i1 = 2; i1 <= 30; i1 += 2) {
 				if ((value & (((0xFF << i1) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i1)))) == value) {
-					return r = 32 - i1;
-					i = (((usqInt) value) >> i1) | ((value << (32 - i1)) & 0xFFFFFFFFUL);
-					n = constant != value;
-					4;
+					return 4;
 
 				}
 			}
@@ -2500,6 +2504,7 @@
 		}
 		return 4 + 4;
 
+
 	case AndCqR:
 	case AndCqRR:
 	case XorCqR:
@@ -2508,16 +2513,12 @@
 		value1 = constant1;
 		while (1) {
 			if ((value1 & 0xFF) == value1) {
-				return n = constant1 != value1;
-				4;
+				return 4;
 
 			}
 			for (i2 = 2; i2 <= 30; i2 += 2) {
 				if ((value1 & (((0xFF << i2) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i2)))) == value1) {
-					return r = 32 - i2;
-					i = (((usqInt) value1) >> i2) | ((value1 << (32 - i2)) & 0xFFFFFFFFUL);
-					n = constant1 != value1;
-					4;
+					return 4;
 
 				}
 			}
@@ -2528,6 +2529,7 @@
 		}
 		return 8;
 
+
 	case OrCqR:
 	case TstCqR:
 	case LoadEffectiveAddressMwrR:
@@ -2536,14 +2538,17 @@
 		constant2 = ((self_in_computeMaximumSize->operands))[0];
 		if ((constant2 & 0xFF) == constant2) {
 			return 4;
+
 		}
 		for (i3 = 2; i3 <= 30; i3 += 2) {
 			if ((constant2 & (((0xFF << i3) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i3)))) == constant2) {
 				return 4;
+
 			}
 		}
 		return 4 + 4;
 
+
 	case MoveCqR:
 		return 4;
 
@@ -2571,13 +2576,16 @@
 
 			if (constant4 >= 0) {
 				return 4;
+
 			}
 			else {
 				return 4;
+
 			}
 		}
 		else {
 			return 4 + 4;
+
 		}
 
 	case MoveMbrR:
@@ -2590,13 +2598,16 @@
 
 			if (constant5 >= 0) {
 				return 4;
+
 			}
 			else {
 				return 4;
+
 			}
 		}
 		else {
 			return 4 + 4;
+
 		}
 
 	case PushCw:
@@ -5722,8 +5733,8 @@
 	case PushCw:
 		/* begin concretizePushCw */
 		word3 = ((self_in_dispatchConcretize->operands))[0];
-		if (((addressIsInInstructions(word3))
-		 || (word3 == (methodLabel())))
+		if (((addressIsInInstructions(((AbstractInstruction *) word3)))
+		 || ((((AbstractInstruction *) word3)) == (methodLabel())))
 		 || (addressIsInCurrentCompilation(word3))) {
 			instrOffset5 = loadCwInto(self_in_dispatchConcretize, ConcreteIPReg);
 		}
@@ -6336,7 +6347,8 @@
 		return AddOpcode;
 
 	default:
-		return error("opcode has no inverse");
+		error("opcode has no inverse");
+		return -1;
 
 	}
 }
@@ -6574,8 +6586,8 @@
     sqInt value;
 
 	operand = ((self_in_loadCwInto->operands))[0];
-	if ((addressIsInInstructions(operand))
-	 || (operand == (methodLabel()))) {
+	if ((addressIsInInstructions(((AbstractInstruction *) operand)))
+	 || ((((AbstractInstruction *) operand)) == (methodLabel()))) {
 		operand = ((((AbstractInstruction *) operand))->address);
 	}
 	if (addressIsInCurrentCompilation(operand)) {
@@ -6615,7 +6627,7 @@
 			 && (distance != 0))) break;
 			value = -distance;
 		}
-		assert(!((isAnInstruction(self_in_loadCwInto, ((self_in_loadCwInto->operands))[0]))));
+		assert(!((isAnInstruction(self_in_loadCwInto, ((AbstractInstruction *) (((self_in_loadCwInto->operands))[0]))))));
 
 	l1:	/* end rotateable8bitSignedImmediate:ifTrue:ifFalse: */;
 	}
@@ -7268,7 +7280,7 @@
 addressIsInCurrentCompilation(sqInt address)
 {
 	return ((((usqInt)address)) >= ((methodLabel->address)))
-	 && (address < (((methodLabel->address)) + (1 << 16)));
+	 && ((((usqInt)address)) < (((methodLabel->address)) + (1 << 16)));
 }
 
 	/* Cogit>>#addressIsInFixups: */
@@ -8353,13 +8365,10 @@
 	return ok;
 }
 
-	/* Cogit>>#checkMaybeObjRefAt: */
+	/* Cogit>>#checkMaybeObjRefInClosedPIC: */
 static sqInt
-checkMaybeObjRefAt(sqInt mcpc)
+checkMaybeObjRefInClosedPIC(sqInt maybeObject)
 {
-    sqInt maybeObject;
-
-	maybeObject = literalBeforeFollowingAddress(backEnd, mcpc);
 	if (maybeObject == 0) {
 		return 1;
 	}
@@ -8379,7 +8388,7 @@
 
 	ok = 1;
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
-	if (!(checkMaybeObjRefAt(pc - (jumpLongByteSize(backEnd))))) {
+	if (!(checkMaybeObjRefInClosedPIC(objRefInClosedPICAt(pc - (jumpLongByteSize(backEnd)))))) {
 		print("object leak in CPIC ");
 		printHex(((sqInt)cPIC));
 		print(" @ ");
@@ -8390,7 +8399,7 @@
 	pc += cPICCaseSize;
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
 		;
-		if (!(checkMaybeObjRefAt(pc - (jumpLongConditionalByteSize(backEnd))))) {
+		if (!(checkMaybeObjRefInClosedPIC(objRefInClosedPICAt(pc - (jumpLongConditionalByteSize(backEnd)))))) {
 			print("object leak in CPIC ");
 			printHex(((sqInt)cPIC));
 			print(" @ ");
@@ -8417,6 +8426,7 @@
     sqInt entryPoint;
     sqInt i;
     sqInt object;
+    sqInt offsetToJump;
     sqInt offsetToLiteral;
     sqInt pc;
     CogMethod *targetMethod;
@@ -8431,9 +8441,10 @@
 
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
 	offsetToLiteral = jumpLongByteSize(backEnd);
+	offsetToJump = BytesPerOop;
 	for (i = 1; i <= ((cPIC->cPICNumCases)); i += 1) {
 		;
-		object = literalBeforeFollowingAddress(backEnd, pc - offsetToLiteral);
+		object = longAt(pc - offsetToLiteral);
 		if ((couldBeObject(object))
 		 && (!(isMarked(object)))) {
 			return 1;
@@ -8441,7 +8452,9 @@
 
 		/* Find target from jump.  Ignore jumps to the interpret and MNU calls within this PIC */
 
-		entryPoint = jumpLongTargetBeforeFollowingAddress(backEnd, pc);
+		entryPoint = jumpLongTargetBeforeFollowingAddress(backEnd, pc - offsetToJump);
+		assert((entryPoint > methodZoneBase)
+		 && (entryPoint < (freeStart())));
 		if (((((usqInt)entryPoint)) < (((usqInt)cPIC)))
 		 || ((((usqInt)entryPoint)) > (((usqInt)((((usqInt)cPIC)) + ((cPIC->blockSize))))))) {
 			targetMethod = ((CogMethod *) (entryPoint - cmNoCheckEntryOffset));
@@ -8452,6 +8465,7 @@
 			}
 		}
 		offsetToLiteral = jumpLongConditionalByteSize(backEnd);
+		offsetToJump = BytesPerOop + 4;
 		pc += cPICCaseSize;
 	}
 	return 0;
@@ -9620,7 +9634,7 @@
 
 	pc = (((((usqInt)cPIC)) + firstCPICCaseOffset) + cPICCaseSize) - (jumpLongConditionalByteSize(backEnd));
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
-		classIndex = literalBeforeFollowingAddress(backEnd, pc - (loadLiteralByteSize(backEnd)));
+		classIndex = longAt(pc - BytesPerOop);
 		if (isForwardedClassIndex(classIndex)) {
 			return 1;
 		}
@@ -10049,14 +10063,14 @@
 	This may be a method reference or null.
 	Answer if the followed literal is young. */
 
-	/* Cogit>>#followMaybeObjRefAt: */
+	/* Cogit>>#followMaybeObjRefInClosedPICAt: */
 static sqInt
-followMaybeObjRefAt(sqInt mcpc)
+followMaybeObjRefInClosedPICAt(sqInt mcpc)
 {
     sqInt object;
     sqInt subject;
 
-	object = literalBeforeFollowingAddress(backEnd, mcpc);
+	object = longAt(mcpc);
 	if (!(couldBeObject(object))) {
 		return 0;
 	}
@@ -10064,7 +10078,8 @@
 		return isYoungObject(object);
 	}
 	subject = followForwarded(object);
-	storeLiteralbeforeFollowingAddress(backEnd, subject, mcpc);
+	/* begin storeObjRef:inClosedPICAt: */
+	longAtput(mcpc, subject);
 	codeModified = 1;
 	return isYoungObject(subject);
 }
@@ -10083,10 +10098,10 @@
     sqInt refersToYoung;
 
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
-	refersToYoung = followMaybeObjRefAt(pc - (jumpLongByteSize(backEnd)));
+	refersToYoung = followMaybeObjRefInClosedPICAt(pc - (jumpLongByteSize(backEnd)));
 	pc += cPICCaseSize;
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
-		if (followMaybeObjRefAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
+		if (followMaybeObjRefInClosedPICAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
 			refersToYoung = 1;
 		}
 		pc += cPICCaseSize;
@@ -10513,14 +10528,14 @@
 generateMapAtstart(sqInt addressOrNull, sqInt startAddress)
 {
     unsigned char annotation;
-    unsigned long delta;
+    sqInt delta;
     sqInt i;
     AbstractInstruction *instruction;
     sqInt length;
-    unsigned long location;
-    unsigned long mapEntry;
+    sqInt location;
+    sqInt mapEntry;
     sqInt maxDelta;
-    unsigned long mcpc;
+    usqInt mcpc;
 
 	length = 0;
 	location = startAddress;
@@ -10531,7 +10546,6 @@
 			/* begin assertValidAnnotation:for: */
 			assert((annotation != (getIsObjectReference()))
 			 || (((instruction->opcode)) == Literal));
-			/* begin mapEntryAddress */
 			mcpc = (((instruction->opcode)) == Literal
 				? (instruction->address)
 				: ((instruction->address)) + ((instruction->machineCodeSize)));
@@ -11234,6 +11248,14 @@
 static void
 initializeBackend(void)
 {
+    AbstractInstruction *existingInst;
+    sqInt i1;
+    sqInt iLimiT;
+    sqInt index;
+    AbstractInstruction *newInst;
+    AbstractInstruction *newLiterals;
+    sqInt operand;
+
 	(methodLabel->machineCodeSize = 0);
 	(methodLabel->opcode = Label);
 	((methodLabel->operands))[0] = 0;
@@ -11243,7 +11265,41 @@
 
 	/* begin allocateLiterals: */
 	if (4 > literalsSize) {
-		literals = realloc(literals, 4 * (sizeof(CogAbstractInstruction)));
+
+		/* Must copy across state (not using realloc, cuz...) and
+		   must also update existing instructions to refer to the new ones...
+		   It's either this or modify all generation routines to be able to retry
+		   with more literals after running out of literals. */
+
+		newLiterals = calloc(4, sizeof(CogAbstractInstruction));
+		if (!(literals == null)) {
+			for (i1 = 0; i1 < nextLiteralIndex; i1 += 1) {
+				existingInst = literalInstructionAt(i1);
+				newInst = (&(newLiterals[i1]));
+				(newInst->opcode = Literal);
+				/* begin operand0: */
+				operand = ((existingInst->operands))[0];
+				((newInst->operands))[0] = operand;
+				newInst;
+				/* begin setLiteralOpcodeIndex: */
+				/* begin literalOpcodeIndex */
+				assert(((existingInst->opcode)) == Literal);
+				index = ((sqInt)(((existingInst->operands))[2]));
+				assert(((newInst->opcode)) == Literal);
+				((newInst->operands))[2] = index;
+				assert(((existingInst->dependent)) == null);
+				(existingInst->dependent = newInst);
+			}
+			for (i1 = 0, iLimiT = (opcodeIndex - 1); i1 <= iLimiT; i1 += 1) {
+				existingInst = abstractInstructionAt(i1);
+				if ((((existingInst->dependent)) != null)
+				 && (((((existingInst->dependent))->opcode)) == Literal)) {
+					(existingInst->dependent = (((existingInst->dependent))->dependent));
+				}
+			}
+		}
+		free(literals);
+		literals = newLiterals;
 		literalsSize = 4;
 	}
 	/* begin resetLiterals: */
@@ -11688,11 +11744,11 @@
     sqInt refersToYoung;
 
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
-	refersToYoung = updateMaybeObjRefAt(pc - (jumpLongByteSize(backEnd)));
+	refersToYoung = updateMaybeObjRefInClosedPICAt(pc - (jumpLongByteSize(backEnd)));
 	pc += cPICCaseSize;
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
 		;
-		if (updateMaybeObjRefAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
+		if (updateMaybeObjRefInClosedPICAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
 			refersToYoung = 1;
 		}
 		pc += cPICCaseSize;
@@ -11710,14 +11766,15 @@
     sqInt i;
     sqInt literal;
     sqInt mappedLiteral;
-    sqInt mcpc;
+    usqInt mcpc;
 
 	for (i = 0; i < runtimeObjectRefIndex; i += 1) {
 		mcpc = objectReferencesInRuntime[i];
-		literal = literalBeforeFollowingAddress(backEnd, ((sqInt)mcpc));
+		literal = longAt(mcpc);
 		mappedLiteral = remapObject(literal);
 		if (mappedLiteral != literal) {
-			storeLiteralbeforeFollowingAddress(backEnd, mappedLiteral, mcpc);
+			/* begin storeLiteral:atAnnotatedAddress:using: */
+			longAtput(mcpc, mappedLiteral);
 			codeModified = 1;
 		}
 	}
@@ -12197,11 +12254,11 @@
 {
     sqInt i;
     sqInt literal;
-    sqInt mcpc;
+    usqInt mcpc;
 
 	for (i = 0; i < runtimeObjectRefIndex; i += 1) {
 		mcpc = objectReferencesInRuntime[i];
-		literal = literalBeforeFollowingAddress(backEnd, ((usqInt)mcpc));
+		literal = longAt(mcpc);
 		markAndTraceLiteralinatpc(literal, ((CogMethod *) null), ((usqInt)mcpc));
 	}
 }
@@ -13520,7 +13577,9 @@
 			if (hasYoungReferent) {
 				error("attempt to generate run-time routine containing young object reference.  Cannot initialize Cogit run-time.");
 			}
-			objectReferencesInRuntime[runtimeObjectRefIndex] = (((sqInt)(((instruction->address)) + ((instruction->machineCodeSize)))));
+			objectReferencesInRuntime[runtimeObjectRefIndex] = (((usqInt)((((instruction->opcode)) == Literal
+	? (instruction->address)
+	: ((instruction->address)) + ((instruction->machineCodeSize))))));
 			runtimeObjectRefIndex += 1;
 		}
 	}
@@ -13754,6 +13813,7 @@
     usqInt cacheAddress;
     sqInt cacheTag;
     sqInt cacheTag1;
+    sqInt callSiteReturnAddress;
     sqInt entryPoint;
     sqInt entryPoint1;
     sqInt entryPoint2;
@@ -13762,7 +13822,6 @@
     sqInt mappedCacheTag;
     sqInt mappedLiteral;
     sqInt mappedOop;
-    char *mcpc1;
     NSSendCache *nsSendCache;
     sqInt oop;
     sqInt *sendTable;
@@ -13788,10 +13847,9 @@
 	}
 	if (annotation == IsNSSendCall) {
 		/* begin nsSendCacheFromReturnAddress: */
-		mcpc1 = ((char *) (((sqInt)mcpc)));
-		entryPoint1 = callTargetFromReturnAddress(backEnd, ((sqInt)mcpc1));
+		entryPoint1 = callTargetFromReturnAddress(backEnd, ((sqInt)mcpc));
 		assert(entryPoint1 < methodZoneBase);
-		cacheAddress = ((usqInt)(implicitReceiveCacheAt(backEnd, mcpc1)));
+		cacheAddress = ((usqInt)(implicitReceiveCacheAt(backEnd, mcpc)));
 		assert(isInOldSpace(cacheAddress));
 		nsSendCache = ((NSSendCache *) cacheAddress);
 		oop = (nsSendCache->selector);
@@ -13837,7 +13895,10 @@
 		 && (couldBeObject(cacheTag1))) {
 			mappedCacheTag = remapObject(cacheTag1);
 			if (cacheTag1 != mappedCacheTag) {
-				rewriteInlineCacheTagat(backEnd, mappedCacheTag, ((sqInt)mcpc));
+				/* begin rewriteInlineCacheTag:at: */
+				callSiteReturnAddress = ((usqInt)mcpc);
+				longAtput(pcRelativeAddressAt(((AbstractInstruction *) backEnd), callSiteReturnAddress - 8), mappedCacheTag);
+				((AbstractInstruction *) backEnd);
 				codeModified = 1;
 			}
 			if ((hasYoungPtr != 0)
@@ -14807,25 +14868,51 @@
 	This may be an object reference, an inline cache tag or null.
 	Answer if the updated literal is young. */
 
-	/* Cogit>>#updateMaybeObjRefAt: */
+	/* Cogit>>#updateMaybeClassRefInClosedPICAt: */
 static sqInt
-updateMaybeObjRefAt(sqInt mcpc)
+updateMaybeClassRefInClosedPICAt(sqInt mcpc)
 {
     sqInt object;
     sqInt subject;
 
-	object = literalBeforeFollowingAddress(backEnd, mcpc);
+	object = longAt(mcpc - BytesPerOop);
 	if (!(couldBeObject(object))) {
 		return 0;
 	}
 	subject = remapOop(object);
 	if (object != subject) {
-		storeLiteralbeforeFollowingAddress(backEnd, subject, mcpc);
+		/* begin storeClassRef:inClosedPICAt: */
+		longAtput(mcpc - BytesPerOop, subject);
 		codeModified = 1;
 	}
 	return isYoungObject(subject);
 }
 
+
+/*	Update a potential object reference from a closed PIC.
+	This may be an object reference, an inline cache tag or null.
+	Answer if the updated literal is young. */
+
+	/* Cogit>>#updateMaybeObjRefInClosedPICAt: */
+static sqInt
+updateMaybeObjRefInClosedPICAt(sqInt mcpc)
+{
+    sqInt object;
+    sqInt subject;
+
+	object = longAt(mcpc);
+	if (!(couldBeObject(object))) {
+		return 0;
+	}
+	subject = remapOop(object);
+	if (object != subject) {
+		/* begin storeObjRef:inClosedPICAt: */
+		longAtput(mcpc, subject);
+		codeModified = 1;
+	}
+	return isYoungObject(subject);
+}
+
 	/* Cogit>>#XorCw:R: */
 static AbstractInstruction *
 gXorCwR(sqInt wordConstant, sqInt reg)
@@ -19131,6 +19218,7 @@
 markAndTraceCacheTagLiteralinatpc(sqInt literal, CogMethod *cogMethodOrNil, usqInt address)
 {
     sqInt objOop;
+    AbstractInstruction * self_in_rewriteInlineCacheTagat;
 
 	if (!(couldBeObject(literal))) {
 		return 0;
@@ -19141,7 +19229,10 @@
 		return 0;
 	}
 	objOop = followForwarded(literal);
-	rewriteInlineCacheTagat(backEnd(), objOop, address);
+	/* begin rewriteInlineCacheTag:at: */
+	self_in_rewriteInlineCacheTagat = ((AbstractInstruction *) (backEnd()));
+	longAtput(pcRelativeAddressAt(self_in_rewriteInlineCacheTagat, address - 8), objOop);
+	self_in_rewriteInlineCacheTagat;
 	markAndTraceUpdatedLiteralin(objOop, cogMethodOrNil);
 	return 1;
 }
@@ -19432,6 +19523,36 @@
 }
 
 
+/*	If possible we generate the method address using pc-relative addressing.
+	If so we don't need to relocate it in code. So check if pc-relative code
+	was generated, and if not, adjust a load literal. There are two cases, a
+	push or a register load. If a push, then there is a register load, but in
+	the instruction
+	before. */
+
+	/* CogOutOfLineLiteralsARMCompiler>>#relocateMethodReferenceBeforeAddress:by: */
+static AbstractInstruction *
+relocateMethodReferenceBeforeAddressby(AbstractInstruction * self_in_relocateMethodReferenceBeforeAddressby, sqInt pc, sqInt delta)
+{
+    sqInt litAddr;
+    sqInt pcPreceedingLoad;
+    sqInt reference;
+
+
+	/* If the load is not done via pc-relative addressing we have to relocate. */
+
+	pcPreceedingLoad = (instructionIsPush(self_in_relocateMethodReferenceBeforeAddressby, longAt(pc - 4))
+		? pc - 4
+		: pc);
+	if (!(isPCRelativeValueLoad(self_in_relocateMethodReferenceBeforeAddressby, longAt(pcPreceedingLoad - 4)))) {
+		litAddr = pcRelativeAddressAt(self_in_relocateMethodReferenceBeforeAddressby, pcPreceedingLoad);
+		reference = longAt(litAddr);
+		longAtput(litAddr, reference + delta);
+	}
+	return self_in_relocateMethodReferenceBeforeAddressby;
+}
+
+
 /*	Rewrite a CallFull or JumpFull instruction to transfer to a different
 	target. This variant is used to rewrite cached primitive calls. Answer the
 	extent of the code change which is used to compute the range of the icache
@@ -19477,6 +19598,18 @@
 }
 
 
+/*	Rewrite an inline cache with a new tag. This variant is used
+	by the garbage collector. */
+
+	/* CogOutOfLineLiteralsARMCompiler>>#rewriteInlineCacheTag:at: */
+static AbstractInstruction *
+rewriteInlineCacheTagat(AbstractInstruction * self_in_rewriteInlineCacheTagat, sqInt cacheTag, sqInt callSiteReturnAddress)
+{
+	longAtput(pcRelativeAddressAt(self_in_rewriteInlineCacheTagat, callSiteReturnAddress - 8), cacheTag);
+	return self_in_rewriteInlineCacheTagat;
+}
+
+
 /*	Size a jump and set its address. The target may be another instruction
 	or an absolute address. On entry the address inst var holds our virtual
 	address. On exit address is set to eventualAbsoluteAddress, which is
@@ -19615,16 +19748,12 @@
 		value = constant;
 		while (1) {
 			if ((value & 0xFF) == value) {
-				return n = constant != value;
-				0;
+				return 0;
 
 			}
 			for (i1 = 2; i1 <= 30; i1 += 2) {
 				if ((value & (((0xFF << i1) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i1)))) == value) {
-					return r = 32 - i1;
-					i = (((usqInt) value) >> i1) | ((value << (32 - i1)) & 0xFFFFFFFFUL);
-					n = constant != value;
-					0;
+					return 0;
 
 				}
 			}
@@ -19634,6 +19763,7 @@
 		}
 		return 1;
 
+
 	case AndCqR:
 	case AndCqRR:
 		/* begin rotateable8bitBitwiseImmediate:ifTrue:ifFalse: */
@@ -19641,16 +19771,12 @@
 		value1 = constant1;
 		while (1) {
 			if ((value1 & 0xFF) == value1) {
-				return n = constant1 != value1;
-				0;
+				return 0;
 
 			}
 			for (i2 = 2; i2 <= 30; i2 += 2) {
 				if ((value1 & (((0xFF << i2) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i2)))) == value1) {
-					return r = 32 - i2;
-					i = (((usqInt) value1) >> i2) | ((value1 << (32 - i2)) & 0xFFFFFFFFUL);
-					n = constant1 != value1;
-					0;
+					return 0;
 
 				}
 			}
@@ -19661,6 +19787,7 @@
 		}
 		return (1 << (highBit(((self_in_usesOutOfLineLiteral->operands))[0]))) != ((((self_in_usesOutOfLineLiteral->operands))[0]) + 1);
 
+
 	case OrCqR:
 	case TstCqR:
 	case LoadEffectiveAddressMwrR:
@@ -19671,30 +19798,29 @@
 		constant2 = ((self_in_usesOutOfLineLiteral->operands))[0];
 		if ((constant2 & 0xFF) == constant2) {
 			return 0;
+
 		}
 		for (i3 = 2; i3 <= 30; i3 += 2) {
 			if ((constant2 & (((0xFF << i3) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i3)))) == constant2) {
 				return 0;
+
 			}
 		}
 		return 1;
 
+
 	case XorCqR:
 		/* begin rotateable8bitBitwiseImmediate:ifTrue:ifFalse: */
 		constant3 = ((self_in_usesOutOfLineLiteral->operands))[0];
 		value2 = constant3;
 		while (1) {
 			if ((value2 & 0xFF) == value2) {
-				return n = constant3 != value2;
-				0;
+				return 0;
 
 			}
 			for (i4 = 2; i4 <= 30; i4 += 2) {
 				if ((value2 & (((0xFF << i4) & 0xFFFFFFFFUL) | (((usqInt) 0xFF) >> (32 - i4)))) == value2) {
-					return r = 32 - i4;
-					i = (((usqInt) value2) >> i4) | ((value2 << (32 - i4)) & 0xFFFFFFFFUL);
-					n = constant3 != value2;
-					0;
+					return 0;
 
 				}
 			}
@@ -19705,9 +19831,10 @@
 		}
 		return 1;
 
+
 	case MoveCwR:
 	case PushCw:
-		return !((isAnInstruction(self_in_usesOutOfLineLiteral, ((self_in_usesOutOfLineLiteral->operands))[0]))
+		return !((isAnInstruction(self_in_usesOutOfLineLiteral, ((AbstractInstruction *) (((self_in_usesOutOfLineLiteral->operands))[0]))))
  || (addressIsInCurrentCompilation(((self_in_usesOutOfLineLiteral->operands))[0])));
 
 	case MoveAwR:
@@ -19732,13 +19859,16 @@
 
 			if (constant4 >= 0) {
 				return 0;
+
 			}
 			else {
 				return 0;
+
 			}
 		}
 		else {
 			return 1;
+
 		}
 
 	case MoveMbrR:
@@ -19752,13 +19882,16 @@
 
 			if (constant5 >= 0) {
 				return 0;
+
 			}
 			else {
 				return 0;
+
 			}
 		}
 		else {
 			return 1;
+
 		}
 
 	default:
@@ -19983,14 +20116,55 @@
 static AbstractInstruction *
 allocateLiteral(sqInt aLiteral)
 {
+    AbstractInstruction *existingInst;
+    sqInt i;
+    sqInt iLimiT;
+    sqInt index;
     sqInt initialNumLiterals;
     AbstractInstruction *litInst;
+    AbstractInstruction *newInst;
+    AbstractInstruction *newLiterals;
+    sqInt operand;
 
 	if (nextLiteralIndex >= literalsSize) {
 		/* begin allocateLiterals: */
 		initialNumLiterals = literalsSize + 8;
 		if (initialNumLiterals > literalsSize) {
-			literals = realloc(literals, initialNumLiterals * (sizeof(CogAbstractInstruction)));
+
+			/* Must copy across state (not using realloc, cuz...) and
+			   must also update existing instructions to refer to the new ones...
+			   It's either this or modify all generation routines to be able to retry
+			   with more literals after running out of literals. */
+
+			newLiterals = calloc(initialNumLiterals, sizeof(CogAbstractInstruction));
+			if (!(literals == null)) {
+				for (i = 0; i < nextLiteralIndex; i += 1) {
+					existingInst = literalInstructionAt(i);
+					newInst = (&(newLiterals[i]));
+					(newInst->opcode = Literal);
+					/* begin operand0: */
+					operand = ((existingInst->operands))[0];
+					((newInst->operands))[0] = operand;
+					newInst;
+					/* begin setLiteralOpcodeIndex: */
+					/* begin literalOpcodeIndex */
+					assert(((existingInst->opcode)) == Literal);
+					index = ((sqInt)(((existingInst->operands))[2]));
+					assert(((newInst->opcode)) == Literal);
+					((newInst->operands))[2] = index;
+					assert(((existingInst->dependent)) == null);
+					(existingInst->dependent = newInst);
+				}
+				for (i = 0, iLimiT = (opcodeIndex - 1); i <= iLimiT; i += 1) {
+					existingInst = abstractInstructionAt(i);
+					if ((((existingInst->dependent)) != null)
+					 && (((((existingInst->dependent))->opcode)) == Literal)) {
+						(existingInst->dependent = (((existingInst->dependent))->dependent));
+					}
+				}
+			}
+			free(literals);
+			literals = newLiterals;
 			literalsSize = initialNumLiterals;
 		}
 	}
@@ -20006,7 +20180,7 @@
 	assert(((litInst->opcode)) == Literal);
 	((litInst->operands))[2] = -1;
 
-	/* Record the opcodeIndex of the first dependent instructuon (the first instruction that references an out-of-line literal) */
+	/* Record the opcodeIndex of the first dependent instruction (the first instruction that references an out-of-line literal) */
 
 	nextLiteralIndex += 1;
 	if (firstOpcodeIndex > opcodeIndex) {
@@ -20035,7 +20209,14 @@
 	return anInstruction;
 }
 
+	/* OutOfLineLiteralsManager>>#classRefInClosedPICAt: */
+static sqInt
+classRefInClosedPICAt(sqInt mcpc)
+{
+	return longAt(mcpc - BytesPerOop);
+}
 
+
 /*	Output all pending literal instructions, making the originals dependents
 	of the generated ones
 	so that a later pass will copy the address of each generated literl inst
@@ -20069,18 +20250,17 @@
 
 
 /*	A literal is in range if its opcode index is within
-	outOfLineLiteralOpcodeLimit, or if
-	its index has yet to be assigned. */
+	outOfLineLiteralOpcodeLimit, or if its index has yet to be assigned. */
 
 	/* OutOfLineLiteralsManager>>#literalInstructionInRange: */
 static sqInt
-literalInstructionInRange(sqInt litInst)
+literalInstructionInRange(AbstractInstruction *litInst)
 {
-    unsigned long opcodeIdx;
+    sqInt opcodeIdx;
 
 	/* begin literalOpcodeIndex */
-	assert((((((AbstractInstruction *) litInst))->opcode)) == Literal);
-	opcodeIdx = (((((AbstractInstruction *) litInst))->operands))[2];
+	assert(((litInst->opcode)) == Literal);
+	opcodeIdx = ((sqInt)(((litInst->operands))[2]));
 	return ((((sqInt)opcodeIdx)) < 0)
 	 || ((assert((getOpcodeIndex()) >= opcodeIdx),
 	(opcodeIndex - opcodeIdx) < (outOfLineLiteralOpcodeLimit(backEnd()))));
@@ -20094,9 +20274,16 @@
 static AbstractInstruction *
 locateLiteral(sqInt aLiteral)
 {
+    AbstractInstruction *existingInst;
     sqInt i;
+    sqInt i1;
+    sqInt iLimiT;
+    sqInt index;
     sqInt initialNumLiterals;
     AbstractInstruction *litInst;
+    AbstractInstruction *newInst;
+    AbstractInstruction *newLiterals;
+    sqInt operand;
 
 	for (i = 0; i < nextLiteralIndex; i += 1) {
 		litInst = literalInstructionAt(i);
@@ -20110,7 +20297,41 @@
 		/* begin allocateLiterals: */
 		initialNumLiterals = literalsSize + 8;
 		if (initialNumLiterals > literalsSize) {
-			literals = realloc(literals, initialNumLiterals * (sizeof(CogAbstractInstruction)));
+
+			/* Must copy across state (not using realloc, cuz...) and
+			   must also update existing instructions to refer to the new ones...
+			   It's either this or modify all generation routines to be able to retry
+			   with more literals after running out of literals. */
+
+			newLiterals = calloc(initialNumLiterals, sizeof(CogAbstractInstruction));
+			if (!(literals == null)) {
+				for (i1 = 0; i1 < nextLiteralIndex; i1 += 1) {
+					existingInst = literalInstructionAt(i1);
+					newInst = (&(newLiterals[i1]));
+					(newInst->opcode = Literal);
+					/* begin operand0: */
+					operand = ((existingInst->operands))[0];
+					((newInst->operands))[0] = operand;
+					newInst;
+					/* begin setLiteralOpcodeIndex: */
+					/* begin literalOpcodeIndex */
+					assert(((existingInst->opcode)) == Literal);
+					index = ((sqInt)(((existingInst->operands))[2]));
+					assert(((newInst->opcode)) == Literal);
+					((newInst->operands))[2] = index;
+					assert(((existingInst->dependent)) == null);
+					(existingInst->dependent = newInst);
+				}
+				for (i1 = 0, iLimiT = (opcodeIndex - 1); i1 <= iLimiT; i1 += 1) {
+					existingInst = abstractInstructionAt(i1);
+					if ((((existingInst->dependent)) != null)
+					 && (((((existingInst->dependent))->opcode)) == Literal)) {
+						(existingInst->dependent = (((existingInst->dependent))->dependent));
+					}
+				}
+			}
+			free(literals);
+			literals = newLiterals;
 			literalsSize = initialNumLiterals;
 		}
 	}
@@ -20123,7 +20344,7 @@
 	assert(((litInst->opcode)) == Literal);
 	((litInst->operands))[2] = -1;
 
-	/* Record the opcodeIndex of the first dependent instructuon (the first instruction that references an out-of-line literal) */
+	/* Record the opcodeIndex of the first dependent instruction (the first instruction that references an out-of-line literal) */
 
 	nextLiteralIndex += 1;
 	if (firstOpcodeIndex > opcodeIndex) {
@@ -20140,6 +20361,13 @@
 	 && ((currentOpcodeIndex - firstOpcodeIndex) >= (outOfLineLiteralOpcodeLimit(backEnd())));
 }
 
+	/* OutOfLineLiteralsManager>>#objRefInClosedPICAt: */
+static sqInt
+objRefInClosedPICAt(sqInt mcpc)
+{
+	return longAt(mcpc);
+}
+
 	/* OutOfLineLiteralsManager>>#resetForBlockCompile */
 static sqInt
 resetForBlockCompile(void)

Modified: branches/Cog/nsspursrc/vm/cogitIA32.c
===================================================================
--- branches/Cog/nsspursrc/vm/cogitIA32.c	2015-06-16 02:42:34 UTC (rev 3376)
+++ branches/Cog/nsspursrc/vm/cogitIA32.c	2015-06-17 03:42:19 UTC (rev 3377)
@@ -1,9 +1,9 @@
 /* Automatically generated by
-	CCodeGenerator VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6
+	CCodeGenerator VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928
    from
-	StackToRegisterMappingCogit VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6
+	StackToRegisterMappingCogit VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928
  */
-static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.1354 uuid: 33807720-0fc7-43d4-98b3-1230281feaf6 " __DATE__ ;
+static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.1361 uuid: 000b1a0b-f89e-415f-aae5-405d3a401928 " __DATE__ ;
 char *__cogitBuildInfo = __buildInfo;
 
 
@@ -33,6 +33,7 @@
  } AbstractInstruction;
 
 #define CogIA32Compiler AbstractInstruction
+#define CogAbstractInstruction AbstractInstruction
 
 
 typedef struct {
@@ -88,6 +89,7 @@
  } BytecodeFixup;
 
 #define CogSSBytecodeFixup BytecodeFixup
+#define CogBytecodeFixup BytecodeFixup
 
 
 typedef struct {
@@ -397,7 +399,7 @@
 static sqInt isAFixup(AbstractInstruction * self_in_isAFixup, void *fixupOrAddress) NoDbgRegParms;
 static sqInt isJump(AbstractInstruction * self_in_isJump) NoDbgRegParms;
 static sqInt isLongJump(AbstractInstruction * self_in_isLongJump) NoDbgRegParms;
-static unsigned long labelOffset(AbstractInstruction * self_in_labelOffset) NoDbgRegParms;
+static usqInt labelOffset(AbstractInstruction * self_in_labelOffset) NoDbgRegParms;
 static sqInt numICacheFlushOpcodes(AbstractInstruction * self_in_numICacheFlushOpcodes) NoDbgRegParms;
 static AbstractInstruction * relocateJumpLongBeforeFollowingAddressby(AbstractInstruction * self_in_relocateJumpLongBeforeFollowingAddressby, sqInt pc, sqInt delta) NoDbgRegParms;
 static AbstractInstruction * resolveJumpTarget(AbstractInstruction * self_in_resolveJumpTarget) NoDbgRegParms;
@@ -522,7 +524,7 @@
 static sqInt checkIfValidOopRefAndTargetpccogMethod(sqInt annotation, char *mcpc, sqInt cogMethod) NoDbgRegParms;
 static sqInt checkIfValidOopRefpccogMethod(sqInt annotation, char *mcpc, sqInt cogMethod) NoDbgRegParms;
 extern sqInt checkIntegrityOfObjectReferencesInCode(sqInt gcModes);
-static sqInt checkMaybeObjRefAt(sqInt mcpc) NoDbgRegParms;
+static sqInt checkMaybeObjRefInClosedPIC(sqInt maybeObject) NoDbgRegParms;
 static sqInt checkValidObjectReferencesInClosedPIC(CogMethod *cPIC) NoDbgRegParms;
 static sqInt closedPICRefersToUnmarkedObject(CogMethod *cPIC) NoDbgRegParms;
 extern char * codeEntryFor(char *address);
@@ -568,7 +570,7 @@
 static sqInt findIsBackwardBranchMcpcBcpcMatchingMcpc(BytecodeDescriptor *descriptor, sqInt isBackwardBranch, char *mcpc, sqInt bcpc, void *targetMcpc) NoDbgRegParms;
 extern void followForwardedLiteralsIn(CogMethod *cogMethod);
 extern void followForwardedMethods(void);
-static sqInt followMaybeObjRefAt(sqInt mcpc) NoDbgRegParms;
+static sqInt followMaybeObjRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static sqInt followMethodReferencesInClosedPIC(CogMethod *cPIC) NoDbgRegParms;
 static void freePICsWithFreedTargets(void);
 extern void freeUnmarkedMachineCode(void);
@@ -714,7 +716,8 @@
 extern void unlinkSendsOfisMNUSelector(sqInt selector, sqInt isMNUSelector);
 extern void unlinkSendsToFree(void);
 extern void unlinkSendsToandFreeIf(sqInt targetMethodObject, sqInt freeIfTrue);
-static sqInt updateMaybeObjRefAt(sqInt mcpc) NoDbgRegParms;
+static sqInt updateMaybeClassRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
+static sqInt updateMaybeObjRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static AbstractInstruction * gXorCwR(sqInt wordConstant, sqInt reg) NoDbgRegParms;
 static void zeroOpcodeIndex(void);
 extern void addAllToYoungReferrers(void);
@@ -855,6 +858,8 @@
 static sqInt registerMask(CogSimStackEntry * self_in_registerMask) NoDbgRegParms;
 static sqInt registerOrNil(CogSimStackEntry * self_in_registerOrNil) NoDbgRegParms;
 static CogSimStackEntry * storeToReg(CogSimStackEntry * self_in_storeToReg, sqInt reg) NoDbgRegParms;
+static sqInt classRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
+static sqInt objRefInClosedPICAt(sqInt mcpc) NoDbgRegParms;
 static sqInt compileBlockDispatch(void);
 static sqInt compileFallbackToInterpreterPrimitive(void);
 static void compileGetErrorCode(void);
@@ -1753,7 +1758,7 @@
 static sqInt numAbstractOpcodes;
 static sqInt numIRCs;
 static sqInt numPICCases;
-static sqInt objectReferencesInRuntime[NumObjRefsInRuntime];
+static usqInt objectReferencesInRuntime[NumObjRefsInRuntime];
 static sqInt opcodeIndex;
 static CogMethod *openPICList = 0;
 static sqInt openPICSize;
@@ -2047,7 +2052,7 @@
 	compileBlockFrameBuild: */
 
 	/* CogAbstractInstruction>>#labelOffset */
-static unsigned long
+static usqInt
 labelOffset(AbstractInstruction * self_in_labelOffset)
 {
 	return ((self_in_labelOffset->operands))[1];
@@ -7731,13 +7736,10 @@
 	return ok;
 }
 
-	/* Cogit>>#checkMaybeObjRefAt: */
+	/* Cogit>>#checkMaybeObjRefInClosedPIC: */
 static sqInt
-checkMaybeObjRefAt(sqInt mcpc)
+checkMaybeObjRefInClosedPIC(sqInt maybeObject)
 {
-    sqInt maybeObject;
-
-	maybeObject = literalBeforeFollowingAddress(backEnd, mcpc);
 	if (maybeObject == 0) {
 		return 1;
 	}
@@ -7757,7 +7759,7 @@
 
 	ok = 1;
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
-	if (!(checkMaybeObjRefAt(pc - (jumpLongByteSize(backEnd))))) {
+	if (!(checkMaybeObjRefInClosedPIC(objRefInClosedPICAt(pc - (jumpLongByteSize(backEnd)))))) {
 		print("object leak in CPIC ");
 		printHex(((sqInt)cPIC));
 		print(" @ ");
@@ -7768,7 +7770,7 @@
 	pc += cPICCaseSize;
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
 		;
-		if (!(checkMaybeObjRefAt(pc - (jumpLongConditionalByteSize(backEnd))))) {
+		if (!(checkMaybeObjRefInClosedPIC(objRefInClosedPICAt(pc - (jumpLongConditionalByteSize(backEnd)))))) {
 			print("object leak in CPIC ");
 			printHex(((sqInt)cPIC));
 			print(" @ ");
@@ -7795,6 +7797,7 @@
     sqInt entryPoint;
     sqInt i;
     sqInt object;
+    sqInt offsetToJump;
     sqInt offsetToLiteral;
     sqInt pc;
     CogMethod *targetMethod;
@@ -7809,9 +7812,10 @@
 
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
 	offsetToLiteral = jumpLongByteSize(backEnd);
+	offsetToJump = 0;
 	for (i = 1; i <= ((cPIC->cPICNumCases)); i += 1) {
 		;
-		object = literalBeforeFollowingAddress(backEnd, pc - offsetToLiteral);
+		object = literalBeforeFollowingAddress(backEnd(), pc - offsetToLiteral);
 		if ((couldBeObject(object))
 		 && (!(isMarked(object)))) {
 			return 1;
@@ -7819,7 +7823,9 @@
 
 		/* Find target from jump.  Ignore jumps to the interpret and MNU calls within this PIC */
 
-		entryPoint = jumpLongTargetBeforeFollowingAddress(backEnd, pc);
+		entryPoint = jumpLongTargetBeforeFollowingAddress(backEnd, pc - offsetToJump);
+		assert((entryPoint > methodZoneBase)
+		 && (entryPoint < (freeStart())));
 		if (((((usqInt)entryPoint)) < (((usqInt)cPIC)))
 		 || ((((usqInt)entryPoint)) > (((usqInt)((((usqInt)cPIC)) + ((cPIC->blockSize))))))) {
 			targetMethod = ((CogMethod *) (entryPoint - cmNoCheckEntryOffset));
@@ -7830,6 +7836,7 @@
 			}
 		}
 		offsetToLiteral = jumpLongConditionalByteSize(backEnd);
+		offsetToJump = 0;
 		pc += cPICCaseSize;
 	}
 	return 0;
@@ -8960,7 +8967,7 @@
 
 	pc = (((((usqInt)cPIC)) + firstCPICCaseOffset) + cPICCaseSize) - (jumpLongConditionalByteSize(backEnd));
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
-		classIndex = literalBeforeFollowingAddress(backEnd, pc - (loadLiteralByteSize(backEnd)));
+		classIndex = literalBeforeFollowingAddress(backEnd(), pc - (loadLiteralByteSize(backEnd())));
 		if (isForwardedClassIndex(classIndex)) {
 			return 1;
 		}
@@ -9389,14 +9396,14 @@
 	This may be a method reference or null.
 	Answer if the followed literal is young. */
 
-	/* Cogit>>#followMaybeObjRefAt: */
+	/* Cogit>>#followMaybeObjRefInClosedPICAt: */
 static sqInt
-followMaybeObjRefAt(sqInt mcpc)
+followMaybeObjRefInClosedPICAt(sqInt mcpc)
 {
     sqInt object;
     sqInt subject;
 
-	object = literalBeforeFollowingAddress(backEnd, mcpc);
+	object = literalBeforeFollowingAddress(backEnd(), mcpc);
 	if (!(couldBeObject(object))) {
 		return 0;
 	}
@@ -9404,7 +9411,8 @@
 		return isYoungObject(object);
 	}
 	subject = followForwarded(object);
-	storeLiteralbeforeFollowingAddress(backEnd, subject, mcpc);
+	/* begin storeObjRef:inClosedPICAt: */
+	storeLiteralbeforeFollowingAddress(backEnd(), subject, mcpc);
 	codeModified = 1;
 	return isYoungObject(subject);
 }
@@ -9423,10 +9431,10 @@
     sqInt refersToYoung;
 
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
-	refersToYoung = followMaybeObjRefAt(pc - (jumpLongByteSize(backEnd)));
+	refersToYoung = followMaybeObjRefInClosedPICAt(pc - (jumpLongByteSize(backEnd)));
 	pc += cPICCaseSize;
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
-		if (followMaybeObjRefAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
+		if (followMaybeObjRefInClosedPICAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
 			refersToYoung = 1;
 		}
 		pc += cPICCaseSize;
@@ -9856,14 +9864,14 @@
 generateMapAtstart(sqInt addressOrNull, sqInt startAddress)
 {
     unsigned char annotation;
-    sqInt delta;
+    usqInt delta;
     sqInt i;
     AbstractInstruction *instruction;
     sqInt length;
-    sqInt location;
-    sqInt mapEntry;
+    usqInt location;
+    usqInt mapEntry;
     sqInt maxDelta;
-    sqInt mcpc;
+    usqInt mcpc;
 
 	length = 0;
 	location = startAddress;
@@ -9872,7 +9880,6 @@
 		annotation = (instruction->annotation);
 		if (!(annotation == null)) {
 			/* begin assertValidAnnotation:for: */
-			/* begin mapEntryAddress */
 			mcpc = ((instruction->address)) + ((instruction->machineCodeSize));
 			while (((delta = (mcpc - location) / 1)) > DisplacementMask) {
 				maxDelta = (((((delta < MaxX2NDisplacement) ? delta : MaxX2NDisplacement)) | DisplacementMask) - DisplacementMask);
@@ -11064,11 +11071,11 @@
     sqInt refersToYoung;
 
 	pc = (((sqInt)cPIC)) + firstCPICCaseOffset;
-	refersToYoung = updateMaybeObjRefAt(pc - (jumpLongByteSize(backEnd)));
+	refersToYoung = updateMaybeObjRefInClosedPICAt(pc - (jumpLongByteSize(backEnd)));
 	pc += cPICCaseSize;
 	for (i = 2; i <= ((cPIC->cPICNumCases)); i += 1) {
 		;
-		if (updateMaybeObjRefAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
+		if (updateMaybeObjRefInClosedPICAt(pc - (jumpLongConditionalByteSize(backEnd)))) {
 			refersToYoung = 1;
 		}
 		pc += cPICCaseSize;
@@ -11086,14 +11093,15 @@
     sqInt i;
     sqInt literal;
     sqInt mappedLiteral;
-    sqInt mcpc;
+    usqInt mcpc;
 
 	for (i = 0; i < runtimeObjectRefIndex; i += 1) {
 		mcpc = objectReferencesInRuntime[i];
-		literal = literalBeforeFollowingAddress(backEnd, ((sqInt)mcpc));
+		literal = literalBeforeFollowingAddress(backEnd, mcpc);
 		mappedLiteral = remapObject(literal);
 		if (mappedLiteral != literal) {
-			storeLiteralbeforeFollowingAddress(backEnd, mappedLiteral, mcpc);
+			/* begin storeLiteral:atAnnotatedAddress:using: */
+			storeLiteralbeforeFollowingAddress(((AbstractInstruction *) backEnd), mappedLiteral, mcpc);
 			codeModified = 1;
 		}
 	}
@@ -11573,11 +11581,11 @@
 {
     sqInt i;
     sqInt literal;
-    sqInt mcpc;
+    usqInt mcpc;
 
 	for (i = 0; i < runtimeObjectRefIndex; i += 1) {
 		mcpc = objectReferencesInRuntime[i];
-		literal = literalBeforeFollowingAddress(backEnd, ((usqInt)mcpc));
+		literal = literalBeforeFollowingAddress(backEnd, mcpc);
 		markAndTraceLiteralinatpc(literal, ((CogMethod *) null), ((usqInt)mcpc));
 	}
 }
@@ -12887,7 +12895,7 @@
 			if (hasYoungReferent) {
 				error("attempt to generate run-time routine containing young object reference.  Cannot initialize Cogit run-time.");
 			}

@@ Diff output truncated at 50000 characters. @@


More information about the Vm-dev mailing list