Skip to content

Commit 658a3a3

Browse files
committed
CogVM source as per VMMaker.oscog-eem.3675/Balloon3D-Plugins-eem.24
Open code compiled code indexing in StackInterpreter>>stObject:at:[put:] to eliminate the double check for compiledMethodFormat that firstValidIndexOfIndexableObject:withFormat: implied. Run InterpreterPrimitives>>primitive[String]At[Put] on the Smalltalk stack. Together this significantly speeds up shape changing when the ClassBuilder runs with MethodMassage (because at:[put:] for CompiledCode is not jitted). Clean up the profiling code in the Cogit. In particular if (as it is by default) the methodObject is being fetched for the prim trace log set newMethod if required, avoiding fetching methodObject twice. Don't pass the argument to ceTakeProfileSample:; instead have ceTakeProfileSample access newMethod which will have been set. When flushing the cache by selector (primitiveFlushCacheBySelector) free any associated Open PIC and rebuild the OpenPIC list. This is arguably over zealous, but otherwise relevant send sites are not really unlinked. Don't fetch callTargetFromReturnAddress: in ceSICMiss:, which with cache flushing changes above results in an erroneous assert fail. Add careful asserts for return from primitives in the Cogit. This pointed to a bug in the SmartSyntaxPluginSimulator (see VMMaker.oscog-eem.3669). Fix comment and variable names in ceStackOverflow:. Fix warnings in method cache and prim log print routines. Use methodReturnValue: in primitiveEnterCriticalSection. Plugins: Add stackMutableObjectValue: (that replaces the unused displayObject in struct VirtualMachine) and use it to implement mutability checks for at least the graphics plugins. Remove some unnecessary remapOop:in: calls given that floatObjectOf:, positive32BitIntegerObjectOf: and makePointwithxValue:yValue: do not fail. Squeak3D: Add mutability checking for the vertex array primitives. Simplify mapVB:ofSize:into: given that floatObjectOf: never fails.
1 parent b5f212d commit 658a3a3

File tree

81 files changed

+21648
-17934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+21648
-17934
lines changed

platforms/Cross/plugins/BochsIA32Plugin/sqBochsIA32Plugin.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,41 @@ resetSegmentRegisters(uintptr_t byteSize, uintptr_t minWriteMaxExecAddr)
163163
return blidx == 0 ? 0 : SomethingLoggedError;
164164
}
165165

166+
/*
167+
* Answer if a 64-bit performance counter is available, storing its value through
168+
* the pointer if so.
169+
* Answer an integer error code if and when something went awry (as specified above).
170+
*/
171+
long
172+
performanceCounter64ofinto(void *cpu, uintptr_t *perfCounterp)
173+
{
174+
BX_CPU_C *anx86 = (BX_CPU_C *)cpu;
175+
176+
if (anx86 != &bx_cpu)
177+
return BadCPUInstance;
178+
179+
*perfCounterp = anx86->timeStampCounter;
180+
181+
return 0;
182+
}
183+
184+
/*
185+
* Answer zero if the 64-bit performance counter could be incremented by increment.
186+
* Answer an integer error code if and when something went awry (as specified above).
187+
*/
188+
long
189+
incrementPerformanceCounter64ofby(void *cpu, uintptr_t increment)
190+
{
191+
BX_CPU_C *anx86 = (BX_CPU_C *)cpu;
192+
193+
if (anx86 != &bx_cpu)
194+
return BadCPUInstance;
195+
196+
anx86->timeStampCounter += increment;
197+
198+
return 0;
199+
}
200+
166201
/*
167202
* Currently a dummy for Bochs.
168203
*/

platforms/Cross/plugins/BochsX64Plugin/sqBochsX64Plugin.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,40 @@ resetSegmentRegisters(uintptr_t byteSize, uintptr_t minWriteMaxExecAddr)
193193
return blidx == 0 ? 0 : SomethingLoggedError;
194194
}
195195

196+
/*
197+
* Answer if a 64-bit performance counter is available, storing its value through
198+
* the pointer if so.
199+
*/
200+
long
201+
performanceCounter64ofinto(void *cpu, uintptr_t *perfCounterp)
202+
{
203+
BX_CPU_C *anx64 = (BX_CPU_C *)cpu;
204+
205+
if (anx64 != &bx_cpu)
206+
return BadCPUInstance;
207+
208+
*perfCounterp = anx64->timeStampCounter;
209+
210+
return 0;
211+
}
212+
213+
/*
214+
* Answer zero if the 64-bit performance counter could be incremented by increment.
215+
* Answer an integer error code if and when something went awry (as specified above).
216+
*/
217+
long
218+
incrementPerformanceCounter64ofby(void *cpu, uintptr_t increment)
219+
{
220+
BX_CPU_C *anx64 = (BX_CPU_C *)cpu;
221+
222+
if (anx64 != &bx_cpu)
223+
return BadCPUInstance;
224+
225+
anx64->timeStampCounter += increment;
226+
227+
return 0;
228+
}
229+
196230
/*
197231
* Currently a dummy for Bochs.
198232
*/

platforms/Cross/plugins/GdbARMPlugin/sqGdbARMPlugin.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <armdefs.h>
2424
#include <armemu.h>
2525

26-
ARMul_State* lastCPU = NULL;
26+
ARMul_State *lastCPU = NULL;
2727

2828
// These two variables exist, in case there are library-functions which write to a stream.
2929
// In that case, we would write functions which print to that stream instead of stderr or similar
@@ -53,7 +53,7 @@ print_state(ARMul_State *state)
5353
(state->prog32Sig == HIGHLOW ? "HIGHLOW" : "???")), state->Emulate);
5454
}
5555

56-
void*
56+
void *
5757
newCPU()
5858
{
5959
if (lastCPU == NULL) ARMul_EmulateInit();
@@ -70,7 +70,7 @@ long
7070
resetCPU(void *cpu)
7171
{
7272
unsigned int i, j;
73-
ARMul_State *state = (ARMul_State*) cpu;
73+
ARMul_State *state = (ARMul_State *)cpu;
7474
// test whether the supplied instance is an ARMul type?
7575

7676
gdblog_index = 0;
@@ -95,7 +95,7 @@ resetCPU(void *cpu)
9595
// See comments in platforms/Cross/plugins/ProcessorSimulatorPlugin.h
9696
static inline long
9797
runOnCPU(ARMul_State *cpu, void *memory,
98-
uintptr_t byteSize, uintptr_t minAddr, uintptr_t minWriteMaxExecAddr, ARMword (*runOrStep)(ARMul_State*))
98+
uintptr_t byteSize, uintptr_t minAddr, uintptr_t minWriteMaxExecAddr, ARMword (*runOrStep)(ARMul_State *))
9999
{
100100
assert(lastCPU == cpu);
101101

@@ -150,6 +150,37 @@ runCPUInSizeMinAddressReadWrite(void *cpu, void *memory,
150150
return runOnCPU(cpu, memory, byteSize, minAddr, minWriteMaxExecAddr, ARMul_DoProg);
151151
}
152152

153+
/*
154+
* Answer if a 64-bit performance counter is available, storing its value through
155+
* the pointer if so.
156+
*/
157+
long
158+
performanceCounter64ofinto(void *cpup, uintptr_t *perfCounterp)
159+
{
160+
ARMul_State *cpu = cpup;
161+
162+
if (lastCPU != cpu)
163+
return BadCPUInstance;
164+
165+
return UnsupportedOperationError;
166+
}
167+
168+
/*
169+
* Answer zero if the 64-bit performance counter could be incremented by increment.
170+
* Answer an integer error code if and when something went awry (as specified above).
171+
*/
172+
long
173+
incrementPerformanceCounter64ofby(void *cpup, uintptr_t increment)
174+
{
175+
ARMul_State *cpu = cpup;
176+
177+
if (lastCPU != cpu)
178+
return BadCPUInstance;
179+
180+
// rather than fail just ignore it. It allows the image to increment the clock without a platform test
181+
return 0;
182+
}
183+
153184
/*
154185
* Currently a dummy for ARM Processor Alien.
155186
*/
@@ -168,10 +199,11 @@ gdb_log_printf(void *stream, const char *format, ...)
168199
int n;
169200
va_start(arg,format);
170201

171-
if (stream == NULL){
172-
n = vsnprintf((char*) (&gdb_log) + gdblog_index, LOGSIZE-gdblog_index, format, arg);
202+
if (!stream) {
203+
n = vsnprintf((char *)(&gdb_log) + gdblog_index, LOGSIZE-gdblog_index, format, arg);
173204
gdblog_index = gdblog_index + n;
174-
} else {
205+
}
206+
else {
175207
vfprintf(stream, format, arg);
176208
}
177209
return 0;

platforms/Cross/plugins/GdbARMv8Plugin/sqGdbARMv8Plugin.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,40 @@ runCPUInSizeMinAddressReadWrite(void *cpu, void *memory,
151151
return runOnCPU(cpu, memory, byteSize, minAddr, minWriteMaxExecAddr, run);
152152
}
153153

154+
/*
155+
* Answer if a 64-bit performance counter is available, storing its value through
156+
* the pointer if so.
157+
*/
158+
long
159+
performanceCounter64ofinto(void *cpup, uintptr_t *perfCounterp)
160+
{
161+
sim_cpu *cpu = cpup;
162+
163+
if (lastCPU != cpu)
164+
return BadCPUInstance;
165+
166+
*perfCounterp = cpu->cntvct;
167+
168+
return 0;
169+
}
170+
171+
/*
172+
* Answer zero if the 64-bit performance counter could be incremented by increment.
173+
* Answer an integer error code if and when something went awry (as specified above).
174+
*/
175+
long
176+
incrementPerformanceCounter64ofby(void *cpup, uintptr_t increment)
177+
{
178+
sim_cpu *cpu = cpup;
179+
180+
if (lastCPU != cpu)
181+
return BadCPUInstance;
182+
183+
cpu->cntvct += increment;
184+
185+
return 0;
186+
}
187+
154188
/*
155189
* Currently a dummy for ARM Processor Alien.
156190
*/

platforms/Cross/plugins/ProcessorSimulatorPlugin.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,16 @@ extern void storeIntegerRegisterStateOfinto(void *cpu, WordType *registerState);
101101
* produces duplicate symbols so use this large hammer, setMinAddresses.
102102
*/
103103
extern void setMinAddresses(uintptr_t mra, uintptr_t mwa);
104+
105+
/*
106+
* Answer zero if a 64-bit performance counter is available, storing its value
107+
* through the pointer if so.
108+
* Answer an integer error code if and when something went awry (as specified above).
109+
*/
110+
extern long performanceCounter64ofinto(void *cpu, uintptr_t *perfCounterp);
111+
112+
/*
113+
* Answer zero if the 64-bit performance counter could be incremented by increment.
114+
* Answer an integer error code if and when something went awry (as specified above).
115+
*/
116+
extern long incrementPerformanceCounter64ofby(void *cpu, uintptr_t increment);

platforms/Cross/vm/sqVirtualMachine.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct VirtualMachine* sqGetInterpreterProxy(void)
9090
VM->pushInteger = pushInteger;
9191
VM->stackFloatValue = stackFloatValue;
9292
VM->stackIntegerValue = stackIntegerValue;
93-
VM->stackObjectValue = stackObjectValue;
93+
VM->stackObjectValue = stackObjectValue; // N.B. see stackMutableObjectValue below
9494
VM->stackValue = stackValue;
9595

9696
/* InterpreterProxy methodsFor: 'object access' */
@@ -156,7 +156,11 @@ struct VirtualMachine* sqGetInterpreterProxy(void)
156156
# else
157157
VM->characterTable = characterTable;
158158
# endif
159+
#if OLD_FOR_REFERENCE
159160
VM->displayObject = displayObject;
161+
#else
162+
VM->stackMutableObjectValue = stackMutableObjectValue; // cf stackObjectValue above
163+
#endif
160164
VM->falseObject = falseObject;
161165
VM->nilObject = nilObject;
162166
VM->trueObject = trueObject;

platforms/Cross/vm/sqVirtualMachine.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ typedef struct VirtualMachine {
123123
/* InterpreterProxy methodsFor: 'special objects' */
124124

125125
sqInt (*characterTable)(void);
126-
sqInt (*displayObject)(void);
126+
#if OLD_FOR_REFERENCE
127+
sqInt (*displayObject)(void); // repurposed
128+
#else /* since there is no legacy plugin problem back to 3.8 we repurpose... */
129+
sqInt (*stackMutableObjectValue)(sqInt offset);
130+
#endif
127131
sqInt (*falseObject)(void);
128132
sqInt (*nilObject)(void);
129133
sqInt (*trueObject)(void);
@@ -397,6 +401,7 @@ sqInt pushInteger(sqInt integerValue);
397401
double stackFloatValue(sqInt offset);
398402
sqInt stackIntegerValue(sqInt offset);
399403
sqInt stackObjectValue(sqInt offset);
404+
sqInt stackMutableObjectValue(sqInt offset);
400405
sqInt stackValue(sqInt offset);
401406

402407
/*** variables ***/
@@ -463,6 +468,9 @@ sqInt isOopMutable(sqInt oop);
463468
sqInt isOopImmutable(sqInt oop);
464469

465470
/* InterpreterProxy methodsFor: 'converting' */
471+
// N.B. there is no booleanObjectOf because testing a boolean and answering either
472+
// trueObject() or falseObject() is faster than passing an argument to a function
473+
// that does the same.
466474
sqInt booleanValueOf(sqInt obj);
467475
sqInt checkedIntegerValueOf(sqInt intOop);
468476
sqInt floatObjectOf(double aFloat);

platforms/minheadless/unix/sqUnixHeartbeat.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,26 @@ ioHighResClock(void)
171171
{
172172
/* return the value of the high performance counter */
173173
sqLong value = 0;
174-
#if defined(__GNUC__) && (defined(i386) || defined(__i386) || defined(__i386__) \
175-
|| defined(x86_64) || defined(__x86_64) || defined (__x86_64__))
174+
175+
#if (defined(__GNUC__) || defined(__SUNPRO_C)) && (defined(i386) || defined(__i386) || defined(__i386__))
176176
__asm__ __volatile__ ("rdtsc" : "=A"(value));
177+
#elif (defined(__GNUC__) || defined(__SUNPRO_C)) && (defined(x86_64) || defined(__x86_64) || defined (__x86_64__))
178+
__asm__ __volatile__ ("rdtsc\n\t" // Returns the time in EDX:EAX.
179+
"shl $32, %%rdx\n\t" // Shift the upper bits left.
180+
"or %%rdx, %0" // 'Or' in the lower bits.
181+
: "=a" (value)
182+
:
183+
: "rdx");
184+
#elif defined(__ARM_ARCH_ISA_A64) || defined(__arm64__) || defined(__aarch64__) || defined(ARM64)
185+
// would prefer to use PMCCNTR_EL0 but at least macOS makes it illegal
186+
__asm__ __volatile__ ("MRS %0, CNTVCT_EL0" : "=r"(value));
177187
#elif defined(__arm__) && (defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_7A__))
178188
/* tpr - do nothing for now; needs input from eliot to decide further */
189+
/* Tim, not sure I have input beyond:
190+
Is there a 64-bit clock on ARM? If so, access it here :-)
191+
*/
192+
#elif defined(__riscv64__)
193+
__asm__ __volatile__ ("rdcycle a0" : "=r"(value));
179194
#else
180195
# error "no high res clock defined"
181196
#endif

platforms/unix/vm/sqUnixHeartbeat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ ioHighResClock(void)
182182
:
183183
: "rdx");
184184
#elif defined(__ARM_ARCH_ISA_A64) || defined(__arm64__) || defined(__aarch64__) || defined(ARM64)
185+
// would prefer to use PMCCNTR_EL0 but at least macOS makes it illegal
185186
__asm__ __volatile__ ("MRS %0, CNTVCT_EL0" : "=r"(value));
186187
#elif defined(__arm__) && (defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_7A__))
187188
/* tpr - do nothing for now; needs input from eliot to decide further */

platforms/unix/vm/sqUnixITimerHeartbeat.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,16 @@ ioHighResClock(void)
170170
: "=a" (value)
171171
:
172172
: "rdx");
173-
#elif defined(__arm64__) || defined(__aarch64__) || defined(ARM64)
174-
__asm__ __volatile__ ("MRS X0, CNTVCT_EL0");
173+
#elif defined(__ARM_ARCH_ISA_A64) || defined(__arm64__) || defined(__aarch64__) || defined(ARM64)
174+
// would prefer to use PMCCNTR_EL0 but at least macOS makes it illegal
175+
__asm__ __volatile__ ("MRS %0, CNTVCT_EL0" : "=r"(value));
175176
#elif defined(__arm__) && (defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_7A__))
176177
/* tpr - do nothing for now; needs input from eliot to decide further */
177178
/* Tim, not sure I have input beyond:
178179
Is there a 64-bit clock on ARM? If so, access it here :-)
179180
*/
180181
#elif defined(__riscv64__)
181-
__asm__ __volatile__ ("rdcycle a0" : "=r"(value));
182+
__asm__ __volatile__ ("rdcycle a0" : "=r"(value));
182183
#else
183184
# error "no high res clock defined"
184185
#endif

0 commit comments

Comments
 (0)