-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMCodeCompactionTest.class.st
631 lines (472 loc) · 22.6 KB
/
VMCodeCompactionTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
Class {
#name : #VMCodeCompactionTest,
#superclass : #VMPrimitiveCallAbstractTest,
#pools : [
'CogRTLOpcodes'
],
#category : #'VMMakerTests-JitTests'
}
{ #category : #tests }
VMCodeCompactionTest >> createBaseFrameWithMachineCodeMethod: aMachineCodeMethod [
"Create the root context with a valid method"
"Let's create a method with enough size. It should have at least a literal (4 or 8 bytes depending the word size) and some bytecodes, so we can put the IP inside the method"
| ctx page aCompiledMethod |
"The context has 5 (in 32 bits) or 9 (in 64 bits) as initial IP, as method has at least one literal"
aCompiledMethod := aMachineCodeMethod methodObject.
ctx := self newSmallContextReceiver: memory nilObject method: aCompiledMethod arguments: #() temporaries: #() ip: cogit entryOffset negated.
"The base context has a trampoline as the savedIP so it can return to a context that is in the heap"
cogit ceBaseFrameReturnTrampoline: 16rAABBCCDD.
page := interpreter makeBaseFrameFor: ctx.
interpreter setStackPointersFromPage: page.
interpreter setStackPageAndLimit: page.
interpreter instructionPointer: interpreter popStack.
"keeping track of the base frame."
baseFrame := interpreter framePointer.
]
{ #category : #utils }
VMCodeCompactionTest >> createFillingMethods: anInteger [
| firstMethod |
firstMethod := self jitMethod: (self findMethod: #methodToCompile1).
2 to: anInteger do: [ :i | self jitMethod: (self findMethod: #methodToCompile1) ].
^ firstMethod
]
{ #category : #tests }
VMCodeCompactionTest >> fillCodeZone [
| aMethod |
[
aMethod := self jitMethod: (self findMethod: #methodToCompile1).
aMethod notNil and: [ | headerSize methodSize |
headerSize := cogit sizeof: CogMethod.
methodSize := headerSize + aMethod blockSize.
(cogit methodZone methodAfter: aMethod) asInteger + methodSize
< cogit methodZone effectiveLimit ] ] whileTrue.
]
{ #category : #running }
VMCodeCompactionTest >> initialCodeSize [
^ 16 * 1024
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactDuringInterpreterPrimitiveThatMovesCurrentMethodWhenShouldNotCrashFromMachineCodeMethod [
| firstMethod compactMethod callerMethod |
<expectedFailure>
"If we have a primitive that forces a code compaction it will crash when not using PrimMaybeCallBack "
"Patching the primitive to execute the method I need to force the code compaction"
"We use the primitive 1 as it has not #maybeCallback"
interpreter primitiveTable at: 1 + 1 put: #primitiveForceMachineCodeCompaction.
cogit sendTrace: 0.
firstMethod := self jitMethod: (self findMethod: #methodToCompile1).
callerMethod := self jitMethod: (self findMethod: #methodToCompile1).
compactMethod := self jitMethod: (self findMethod: #methodThatCallPrimitive1:).
self fillCodeZone.
firstMethod cmUsageCount: 0.
self createBaseFrameWithMachineCodeMethod: callerMethod.
"Initialize Stack to the correct pointers in the selected page"
machineSimulator smalltalkStackPointerRegisterValue: interpreter stackPointer.
machineSimulator framePointerRegisterValue: interpreter framePointer.
machineSimulator baseRegisterValue: cogit varBaseAddress.
cogit setCStackPointer: interpreter rumpCStackAddress.
cogit setCFramePointer: interpreter rumpCStackAddress.
self prepareStackForSendReceiver: memory nilObject arguments: {memory falseObject}.
machineSimulator instructionPointerRegisterValue: compactMethod address + cogit noCheckEntryOffset.
self runFrom: compactMethod address + cogit noCheckEntryOffset until: callerAddress.
self assert: machineSimulator receiverRegisterValue equals: memory trueObject.
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactDuringInterpreterPrimitiveThatMovesCurrentMethodWhenUsingPrimCallMayCallBackShouldNotCrashFromMachineCodeMethod [
| firstMethod compactMethod callerMethod |
"Patching the primitive to execute the method I need to force the code compaction
We use the primitive 173 as it is marked as mayCallBack"
interpreter primitiveTable at: 1 + 173 put: #primitiveForceMachineCodeCompaction.
cogit sendTrace: 0.
firstMethod := self jitMethod: (self findMethod: #methodToCompile1).
callerMethod := self jitMethod: (self findMethod: #methodToCompile1).
compactMethod := self jitMethod: (self findMethod: #methodThatCallPrimitive173:).
self fillCodeZone.
firstMethod cmUsageCount: 0.
self createBaseFrameWithMachineCodeMethod: callerMethod.
"Initialize Stack to the correct pointers in the selected page"
machineSimulator smalltalkStackPointerRegisterValue: interpreter stackPointer.
machineSimulator framePointerRegisterValue: interpreter framePointer.
machineSimulator baseRegisterValue: cogit varBaseAddress.
cogit setCStackPointer: interpreter rumpCStackAddress.
cogit setCFramePointer: interpreter rumpCStackAddress.
self prepareStackForSendReceiver: memory nilObject arguments: {memory falseObject}.
machineSimulator instructionPointerRegisterValue: compactMethod address + cogit noCheckEntryOffset.
self runFrom: compactMethod address + cogit noCheckEntryOffset until: callerAddress.
self assert: machineSimulator receiverRegisterValue equals: memory trueObject.
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingAnUnusedMethodCompactsRemainingMethodToTheBeginning [
| firstMethod compactMethod methodOop |
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
compactMethod := self jitMethod: (self findMethod: #methodThatCallPrimitive1:) selector: memory falseObject.
self fillCodeZone.
methodOop := compactMethod methodObject.
firstMethod cmUsageCount: 0.
compactMethod cmUsageCount: 5.
self createBaseFrame.
self assert: (interpreter cogMethodOf: methodOop) equals: compactMethod address.
interpreter commenceCogCompiledCodeCompaction.
self assert: (interpreter cogMethodOf: methodOop) equals: firstMethod address
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocateInSendsLiterals [
| firstMethod cogMethod methodOop |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
firstMethod cmUsageCount: 0.
"Method that will be linked to"
cogMethod := self jitMethod: (self findMethod: #methodSendingNilArgument) selector: memory falseObject.
cogMethod cmUsageCount: 4.
methodOop := cogMethod methodObject.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
"Launch code compaction"
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the callee entry offset"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject.
self
runFrom: (interpreter cogMethodOf: methodOop) address + cogit noCheckEntryOffset
until: send1TrampolineAddress.
"In StackToRegisterMappingCogit the argument came in the registerArg0"
self
assert: machineSimulator arg0RegisterValue
equals: memory nilObject
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocateLiterals [
| firstMethod cogMethod methodOop |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
firstMethod cmUsageCount: 0.
"Method that will be linked to"
cogMethod := self jitMethod: (self findMethod: #methodReturningNil) selector: memory falseObject.
cogMethod cmUsageCount: 4.
methodOop := cogMethod methodObject.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
"Launch code compaction"
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the callee entry offset"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject.
self
runFrom: (interpreter cogMethodOf: methodOop) address + cogit noCheckEntryOffset
until: callerAddress.
self
assert: machineSimulator receiverRegisterValue
equals: memory nilObject
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocateMethodReference [
| firstMethod cogMethod methodOop |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
firstMethod cmUsageCount: 0.
cogMethod := self jitMethod: (self findMethod: #methodWithSend) selector: memory falseObject.
cogMethod cmUsageCount: 4.
methodOop := cogMethod methodObject.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
"Compact"
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the trampoline and should have created a frame with the right method"
self createFramefulCallFrom: callerAddress.
self pushAddress: memory falseObject.
self
runFrom: (interpreter cogMethodOf: methodOop) address + cogit noCheckEntryOffset
until: sendTrampolineAddress.
"Assert that activating the method should have pushed the right method to the stack"
self
assert: (interpreter mframeHomeMethod: (machineSimulator framePointerRegisterValue))
equals: (interpreter cogMethodOf: methodOop)
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocateMonomorphicCallsite [
| firstMethod callerMethodOop calleeCogMethod selector callerCogMethod calleeMethodOop |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
firstMethod cmUsageCount: 0.
"Method that will be linked to"
calleeCogMethod := self jitMethod: (self findMethod: #methodThatCallPrimitive1:) selector: memory falseObject.
calleeCogMethod cmUsageCount: 4.
calleeMethodOop := calleeCogMethod methodObject.
selector := memory falseObject.
callerCogMethod := self jitMethod: (self findMethod: #methodWithSend) selector: selector.
callerCogMethod cmUsageCount: 4.
callerMethodOop := callerCogMethod methodObject.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
"Setup the frame to do the patch"
"Push receiver then send, to finally stop at the trampoline and patch the call-site"
self createFramefulCallFrom: callerAddress.
self pushAddress: memory falseObject.
self runFrom: callerCogMethod address + cogit noCheckEntryOffset until: sendTrampolineAddress.
cogit
linkSendAt: machineSimulator getReturnAddress
in: callerMethodOop
to: calleeCogMethod
offset: cogit entryOffset
receiver: memory falseObject.
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the callee entry offset"
self createFramefulCallFrom: callerAddress.
self pushAddress: memory falseObject.
self
runFrom: (interpreter cogMethodOf: callerMethodOop) address + cogit noCheckEntryOffset
until: (interpreter cogMethodOf: calleeMethodOop) asInteger + cogit entryOffset.
self
assert: machineSimulator instructionPointerRegisterValue
equals: (interpreter cogMethodOf: calleeMethodOop) asInteger + cogit entryOffset
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocatePolymorphicPICCallsite [
"This method sets up a method A that is linked to a polymorphic PIC linked to B and C.
Code compaction is launched so both A, B, C and the PIC are moved and remapped.
Re-sending a message should still work and arrive to all cases of the PIC after remap."
| firstMethod callerMethodOop calleeCogMethod selector callerCogMethod calleeMethodOop calleeCogMethod2 calleeMethodOop2 pic |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
firstMethod cmUsageCount: 0.
"Caller that will be linked to the PIC"
selector := memory falseObject.
callerCogMethod := self jitMethod: (self findMethod: #methodWithSend:) selector: selector.
callerCogMethod cmUsageCount: 4.
callerMethodOop := callerCogMethod methodObject.
"Methods that will be linked to"
calleeCogMethod := self jitMethod: (self findMethod: #methodWithSend) selector: selector.
calleeCogMethod cmUsageCount: 4.
calleeMethodOop := calleeCogMethod methodObject.
calleeCogMethod2 := self jitMethod: (self findMethod: #methodWithSend) selector: selector.
calleeCogMethod2 cmUsageCount: 4.
calleeMethodOop2 := calleeCogMethod2 methodObject.
"Setup the frame to do the patch"
"Push receiver then send, to finally stop at the trampoline and patch the call-site"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject arguments: { memory falseObject }.
self runFrom: callerCogMethod address + cogit noCheckEntryOffset until: sendTrampolineAddress.
"First monomorphic link"
cogit
linkSendAt: machineSimulator getReturnAddress
in: callerMethodOop
to: calleeCogMethod
offset: cogit entryOffset
receiver: memory falseObject.
"Then create the PIC and link it"
pic := cogit cogPICSelector: selector
numArgs: 1
Case0Method: calleeCogMethod
Case1Method: calleeMethodOop2
tag: (cogit objectRepresentation inlineCacheTagForInstance: (memory integerObjectOf: 7))
isMNUCase: false.
pic cmUsageCount: 4.
cogit backEnd
rewriteCallAt: machineSimulator getReturnAddress
target: pic asInteger + cogit entryOffset.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the callee entry offset"
"Check case 1"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject arguments: { memory falseObject }.
self
runFrom: (interpreter cogMethodOf: callerMethodOop) address + cogit noCheckEntryOffset
until: (interpreter cogMethodOf: calleeMethodOop) asInteger + cogit noCheckEntryOffset.
self
assert: machineSimulator instructionPointerRegisterValue
equals: (interpreter cogMethodOf: calleeMethodOop) asInteger + cogit noCheckEntryOffset.
"Check case 2"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject arguments: { memory integerObjectOf: 7 }.
self
runFrom: (interpreter cogMethodOf: callerMethodOop) address + cogit noCheckEntryOffset
until: (interpreter cogMethodOf: calleeMethodOop2) asInteger + cogit noCheckEntryOffset.
self
assert: machineSimulator instructionPointerRegisterValue
equals: (interpreter cogMethodOf: calleeMethodOop2) asInteger + cogit noCheckEntryOffset.
"Check PIC MISS trampoline"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject arguments: { memory characterObjectOf: 7 }.
self
runFrom: (interpreter cogMethodOf: callerMethodOop) address + cogit noCheckEntryOffset
until: cogit ceCPICMissTrampoline.
self
assert: machineSimulator instructionPointerRegisterValue
equals: cogit ceCPICMissTrampoline
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocatePolymorphicPICInterpreterAbortCallsite [
"This method sets up a method A that is linked to a polymorphic PIC linked to B and C.
Code compaction is launched so both A, B, C and the PIC are moved and remapped.
Re-sending a message should still work and arrive to all cases of the PIC after remap."
| firstMethod callerMethodOop calleeCogMethod selector callerCogMethod calleeMethodOop calleeCogMethod2 calleeMethodOop2 pic |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self
jitMethod: (self findMethod: #methodToCompile1)
selector: memory trueObject.
firstMethod cmUsageCount: 0.
"Caller that will be linked to the PIC"
selector := memory falseObject.
callerCogMethod := self
jitMethod: (self findMethod: #methodWithSend:)
selector: selector.
callerCogMethod cmUsageCount: 4.
callerMethodOop := callerCogMethod methodObject.
"Methods that will be linked to"
calleeCogMethod := self
jitMethod: (self findMethod: #methodWithSend)
selector: selector.
calleeCogMethod cmUsageCount: 4.
calleeMethodOop := calleeCogMethod methodObject.
calleeMethodOop2 := methodBuilder
fillFromPharoMethod:
(self findMethod: #methodWithSend);
buildMethod.
"Setup the frame to do the patch"
"Push receiver then send, to finally stop at the trampoline and patch the call-site"
self createFramefulCallFrom: callerAddress.
self
prepareStackForSendReceiver: memory falseObject
arguments: { memory falseObject }.
self
runFrom: callerCogMethod address + cogit noCheckEntryOffset
until: sendTrampolineAddress.
"First monomorphic link"
cogit
linkSendAt: machineSimulator getReturnAddress
in: callerMethodOop
to: calleeCogMethod
offset: cogit entryOffset
receiver: memory falseObject.
"Then create the PIC and link it"
interpreter setBreakSelectorLength: memory minSmallInteger.
pic := cogit
cogPICSelector: selector
numArgs: 1
Case0Method: calleeCogMethod
Case1Method: calleeMethodOop2
tag: (cogit objectRepresentation inlineCacheTagForInstance:
(memory integerObjectOf: 7))
isMNUCase: false.
pic cmUsageCount: 4.
cogit backEnd
rewriteCallAt: machineSimulator getReturnAddress
target: pic asInteger + cogit entryOffset.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the callee entry offset"
"Check case 2"
self createFramefulCallFrom: callerAddress.
self
prepareStackForSendReceiver: memory falseObject
arguments: { (memory integerObjectOf: 7) }.
self
runFrom: (interpreter cogMethodOf: callerMethodOop) address
+ cogit noCheckEntryOffset
until: cogit cePICAbortTrampoline.
self
assert: machineSimulator instructionPointerRegisterValue
equals: cogit cePICAbortTrampoline
]
{ #category : #tests }
VMCodeCompactionTest >> testCompactingShouldRelocatePolymorphicPICMNUAbortCallsite [
"This method sets up a method A that is linked to a polymorphic PIC linked to B and C.
Code compaction is launched so both A, B, C and the PIC are moved and remapped.
Re-sending a message should still work and arrive to all cases of the PIC after remap."
| firstMethod callerMethodOop calleeCogMethod selector callerCogMethod calleeMethodOop calleeCogMethod2 calleeMethodOop2 pic |
"Create a method that will be collected and force compaction of all the next ones"
firstMethod := self jitMethod: (self findMethod: #methodToCompile1) selector: memory trueObject.
firstMethod cmUsageCount: 0.
"Caller that will be linked to the PIC"
selector := memory falseObject.
callerCogMethod := self jitMethod: (self findMethod: #methodWithSend:) selector: selector.
callerCogMethod cmUsageCount: 4.
callerMethodOop := callerCogMethod methodObject.
"Methods that will be linked to"
calleeCogMethod := self jitMethod: (self findMethod: #methodWithSend) selector: selector.
calleeCogMethod cmUsageCount: 4.
calleeMethodOop := calleeCogMethod methodObject.
calleeCogMethod2 := self jitMethod: (self findMethod: #methodWithSend) selector: selector.
calleeCogMethod2 cmUsageCount: 4.
calleeMethodOop2 := calleeCogMethod2 methodObject.
"Setup the frame to do the patch"
"Push receiver then send, to finally stop at the trampoline and patch the call-site"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject arguments: { memory falseObject }.
self runFrom: callerCogMethod address + cogit noCheckEntryOffset until: sendTrampolineAddress.
"First monomorphic link"
cogit
linkSendAt: machineSimulator getReturnAddress
in: callerMethodOop
to: calleeCogMethod
offset: cogit entryOffset
receiver: memory falseObject.
"Then create the PIC and link it"
interpreter setBreakSelectorLength: memory minSmallInteger.
pic := cogit cogPICSelector: selector
numArgs: 1
Case0Method: calleeCogMethod
Case1Method: calleeMethodOop2
tag: (cogit objectRepresentation inlineCacheTagForInstance: (memory integerObjectOf: 7))
isMNUCase: true.
pic cmUsageCount: 4.
cogit backEnd
rewriteCallAt: machineSimulator getReturnAddress
target: pic asInteger + cogit entryOffset.
"Fill the code zone with more methods to force compaction"
self fillCodeZone.
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"After compaction the send should arrive to the callee entry offset"
"Check case 2"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: memory falseObject arguments: { memory integerObjectOf: 7 }.
self
runFrom: (interpreter cogMethodOf: callerMethodOop) address + cogit noCheckEntryOffset
until: cogit cePICAbortTrampoline.
self
assert: machineSimulator instructionPointerRegisterValue
equals: cogit cePICAbortTrampoline
]
{ #category : #tests }
VMCodeCompactionTest >> testRelocatingAMethodDoesNotAffectTheFrameCreationPushes [
| firstMethod compactMethod methodOop readOnlyObject |
firstMethod := self createFillingMethods: 10.
"We are using this method because it modifies an instance variable"
compactMethod := self jitMethod: (ZnEncodedStream lookupSelector: #on:).
compactMethod cmUsageCount: 4.
methodOop := compactMethod methodObject.
self fillCodeZone.
self createBaseFrame.
interpreter commenceCogCompiledCodeCompaction.
"Obtaining the relocated method"
compactMethod := interpreter cogMethodOf: methodOop.
"The receiver should be a read only, so it will create the frame and call the routine"
readOnlyObject := self newObjectWithSlots: 1.
memory setIsImmutableOf: readOnlyObject to: true.
"We create to activate the method"
self createFramefulCallFrom: callerAddress.
self prepareStackForSendReceiver: readOnlyObject arguments: { memory falseObject }.
"We run until the ceStoreTrampoline"
self
runFrom: compactMethod address + cogit noCheckEntryOffset
until: (cogit objectRepresentation ceStoreTrampolines at: 0).
"To access to the stack we need to put in sync the pointers"
interpreter stackPointer: machineSimulator smalltalkStackPointerRegisterValue.
interpreter framePointer: machineSimulator framePointerRegisterValue.
machineSimulator hasLinkRegister
ifFalse: [ interpreter popStack. ].
"Asserting the correct structure of the created frame"
self assert: interpreter stackTop equals: readOnlyObject.
self assert: (interpreter stackValue: 1) equals: memory nilObject.
self assert: (interpreter stackValue: 2) equals: compactMethod address.
]