-
Notifications
You must be signed in to change notification settings - Fork 67
/
CogObjectRepresentationForSpur.class.st
3352 lines (2905 loc) · 128 KB
/
CogObjectRepresentationForSpur.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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Class {
#name : #CogObjectRepresentationForSpur,
#superclass : #CogObjectRepresentation,
#instVars : [
'ceScheduleScavengeTrampoline',
'ceSmallActiveContextInMethodTrampoline',
'ceSmallActiveContextInFullBlockTrampoline',
'ceLargeActiveContextInMethodTrampoline',
'ceLargeActiveContextInFullBlockTrampoline',
'ceStoreCheckContextReceiverTrampoline',
'ceStoreTrampolines',
'ceNewHashTrampoline',
'ceInlineNewHashTrampoline'
],
#classVars : [
'CheckRememberedInTrampoline',
'NumStoreTrampolines'
],
#pools : [
'VMBytecodeConstants',
'VMClassIndices'
],
#category : #'VMMaker-JIT'
}
{ #category : #translation }
CogObjectRepresentationForSpur class >> declareCVarsIn: aCodeGen [
"Deal wuth the fact that the number of trampolines depends on IMMUTABILITY
and that IMMUTABILITY can be defined at compile time. Yes, this is a mess."
| current values |
current := InitializationOptions at: #IMMUTABILITY ifAbsent: nil.
values := #(true false) collect:
[:bool|
InitializationOptions at: #IMMUTABILITY put: bool.
self cogitClass initializeNumTrampolines.
(Cogit classPool at: #NumTrampolines) printString].
current
ifNil: [InitializationOptions removeKey: #IMMUTABILITY]
ifNotNil: [InitializationOptions at: #IMMUTABILITY put: current].
values first ~= values last ifTrue:
[aCodeGen addConstantForBinding: #NumTrampolines -> ('(IMMUTABILITY ? ' , values first , ' : ' , values last , ')')].
aCodeGen
var: #ceStoreTrampolines
declareC: ('#if IMMUTABILITY\sqInt ceStoreTrampolines[', NumStoreTrampolines printString, '];\#endif') withCRs
]
{ #category : #'class initialization' }
CogObjectRepresentationForSpur class >> initialize [
"Number of trampolines for the combined IMMUTABILITY/store check instance variable store.
Trampolines from 0 to NumStoreTrampolines - 2 are dedicated to an inst var index, the last one is generic."
NumStoreTrampolines := 5
]
{ #category : #initialization }
CogObjectRepresentationForSpur class >> initializeMiscConstants [
CheckRememberedInTrampoline := InitializationOptions at: #CheckRememberedInTrampoline ifAbsent: [false]
]
{ #category : #accessing }
CogObjectRepresentationForSpur class >> numTrampolines [
^super numTrampolines
+ (SistaV1BytecodeSet
ifTrue: [9] "(small,large)x(method,block,fullBlock) context creation,
ceNewHashTrampoline, ceStoreCheckContextReceiverTrampoline and ceScheduleScavengeTrampoline"
ifFalse: [7] "(small,large)x(method,block) context creation,
ceNewHashTrampoline, ceStoreCheckContextReceiverTrampoline and ceScheduleScavengeTrampoline")
+ NumStoreTrampolines
+ (SistaVM
ifTrue: [1] "inline newHash"
ifFalse: [0])
]
{ #category : #'garbage collection' }
CogObjectRepresentationForSpur >> allYoungObjectsAgeInFullGC [
^false
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> branchIf: reg instanceOfBehavior: classObj target: targetFixUp [
"Generate a branch if reg is an instance of classObj, otherwise fall-
through. Cannot change the value of reg (may be used afterwards)."
| classIndex jmp |
<inline: true>
<var: #targetFixUp type: #'AbstractInstruction *'>
<var: #jmp type: #'AbstractInstruction *'>
classIndex := objectMemory classTagForClass: classObj.
classIndex = (objectMemory fetchClassTagOf: objectMemory falseObject)
ifTrue: [ self branchIf: reg isOop: objectMemory falseObject target: targetFixUp ].
classIndex = (objectMemory fetchClassTagOf: objectMemory trueObject)
ifTrue: [ self branchIf: reg isOop: objectMemory trueObject target: targetFixUp ].
classIndex = (objectMemory fetchClassTagOf: objectMemory nilObject)
ifTrue: [ self branchIf: reg isOop: objectMemory nilObject target: targetFixUp ].
(objectMemory isImmediateClass: classObj)
ifTrue:
[self branchIf: reg hasImmediateTag: classIndex target: targetFixUp ]
ifFalse:
[jmp := (self genJumpImmediate: reg) .
self genGetClassIndexOfNonImm: reg into: TempReg.
self genCmpClassIndex: classIndex R: TempReg.
cogit JumpZero: targetFixUp.
jmp jmpTarget: cogit Label ].
^0
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> branchIf: reg instanceOfBehaviors: arrayObj target: targetFixUp [
"Generate a branch if reg is an instance of any of the classes in arrayObj,
otherwise fall-through. reg should not be edited."
| allImmediate noneImmediate immediateMask numNonImmediates classObj |
<var: #targetFixUp type: #'AbstractInstruction *'>
"let me tell you all about it, let me falsify"
allImmediate := true. noneImmediate := true. immediateMask := 0. numNonImmediates := 0.
0 to: (objectMemory numSlotsOf: arrayObj) - 1 do:
[:i|
classObj := objectMemory fetchPointer: i ofObject: arrayObj.
(objectMemory isImmediateClass: classObj)
ifTrue:
[noneImmediate := false.
immediateMask := immediateMask + (objectMemory classTagForClass: classObj)]
ifFalse:
[allImmediate := false.
numNonImmediates := numNonImmediates + 1]].
noneImmediate ifTrue: [ ^ self noneImmediateBranchIf: reg instanceOfBehaviors: arrayObj target: targetFixUp ].
allImmediate ifTrue: [ ^ self allImmediate: immediateMask branchIf: reg instanceOfBehaviors: arrayObj target: targetFixUp ].
^ self mixed: numNonImmediates branchIf: reg instanceOfBehaviors: arrayObj target: targetFixUp
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> branchIf: reg isNotOop: oop target: targetFixUp [
<var: #targetFixUp type: #'AbstractInstruction *'>
<inline: true>
cogit CmpCq: oop R: reg.
cogit JumpNonZero: targetFixUp.
^0
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> branchIf: reg isOop: oop target: targetFixUp [
<var: #targetFixUp type: #'AbstractInstruction *'>
<inline: true>
cogit CmpCq: oop R: reg.
cogit JumpZero: targetFixUp.
^0
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> branchIf: reg notInstanceOfBehavior: classObj target: targetFixUp [
"Generate a branch if reg is an instance of classObj, otherwise fall-
through. Cannot change the value of reg (may be used afterwards)."
| classIndex |
<inline: true>
<var: #targetFixUp type: #'AbstractInstruction *'>
classIndex := objectMemory classTagForClass: classObj.
classIndex = (objectMemory fetchClassTagOf: objectMemory falseObject)
ifTrue: [ self branchIf: reg isNotOop: objectMemory falseObject target: targetFixUp ].
classIndex = (objectMemory fetchClassTagOf: objectMemory trueObject)
ifTrue: [ self branchIf: reg isNotOop: objectMemory trueObject target: targetFixUp ].
classIndex = (objectMemory fetchClassTagOf: objectMemory nilObject)
ifTrue: [ self branchIf: reg isNotOop: objectMemory nilObject target: targetFixUp ].
(objectMemory isImmediateClass: classObj)
ifTrue:
[self branchIf: reg hasNotImmediateTag: classIndex target: targetFixUp ]
ifFalse:
[(self genJumpImmediate: reg) jmpTarget: targetFixUp.
self genGetClassIndexOfNonImm: reg into: TempReg.
self genCmpClassIndex: classIndex R: TempReg.
cogit JumpNonZero: targetFixUp ].
^0
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> branchIf: reg notInstanceOfBehaviors: arrayObj target: targetFixUp [
"Generate a branch if reg is an instance of any of the classes in arrayObj,
otherwise fall-through. reg should not be edited."
| allImmediate noneImmediate immediateMask numNonImmediates classObj |
<var: #targetFixUp type: #'AbstractInstruction *'>
"let me tell you all about it, let me falsify"
allImmediate := true. noneImmediate := true. immediateMask := 0. numNonImmediates := 0.
0 to: (objectMemory numSlotsOf: arrayObj) - 1 do:
[:i|
classObj := objectMemory fetchPointer: i ofObject: arrayObj.
(objectMemory isImmediateClass: classObj)
ifTrue:
[noneImmediate := false.
immediateMask := immediateMask + (objectMemory classTagForClass: classObj)]
ifFalse:
[allImmediate := false.
numNonImmediates := numNonImmediates + 1]].
noneImmediate ifTrue: [ ^ self noneImmediateBranchIf: reg notInstanceOfBehaviors: arrayObj target: targetFixUp ].
allImmediate ifTrue: [ ^ self allImmediate: immediateMask branchIf: reg notInstanceOfBehaviors: arrayObj target: targetFixUp ].
^ self mixed: numNonImmediates branchIf: reg notInstanceOfBehaviors: arrayObj target: targetFixUp
]
{ #category : #'garbage collection' }
CogObjectRepresentationForSpur >> cacheTagIsMarked: cacheTag [
"Answer if the cacheTag is not unmarked, i.e. answer true for compact class
indices and immediates; only answer false for unmarked objects. In Spur
linked send cache tags are class indices so effectively they're always marked."
^true
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> callStoreCheckTrampoline [
cogit CallRT: ceStoreCheckTrampoline
]
{ #category : #testing }
CogObjectRepresentationForSpur >> canPinObjects [
"Answer if the memory manager supports pinned objects."
^true
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceLargeActiveContextInFullBlockTrampoline [
<doNotGenerate>
^ ceLargeActiveContextInFullBlockTrampoline
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceLargeActiveContextInFullBlockTrampoline: anInteger [
<doNotGenerate>
ceLargeActiveContextInFullBlockTrampoline := anInteger
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceLargeActiveContextInMethodTrampoline [
<doNotGenerate>
^ ceLargeActiveContextInMethodTrampoline
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceLargeActiveContextInMethodTrampoline: anInteger [
<doNotGenerate>
ceLargeActiveContextInMethodTrampoline := anInteger
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceScheduleScavengeTrampoline: anAddress [
<doNotGenerate>
ceScheduleScavengeTrampoline := anAddress
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceSmallActiveContextInFullBlockTrampoline [
<doNotGenerate>
^ ceSmallActiveContextInFullBlockTrampoline
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceSmallActiveContextInFullBlockTrampoline: anInteger [
<doNotGenerate>
ceSmallActiveContextInFullBlockTrampoline := anInteger
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceSmallActiveContextInMethodTrampoline [
<doNotGenerate>
^ ceSmallActiveContextInMethodTrampoline
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceSmallActiveContextInMethodTrampoline: anInteger [
<doNotGenerate>
ceSmallActiveContextInMethodTrampoline := anInteger
]
{ #category : #accessing }
CogObjectRepresentationForSpur >> ceStoreCheckTrampoline [
^ ceStoreCheckTrampoline
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> ceStoreTrampolines [
^ ceStoreTrampolines
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> checkRememberedInTrampoline [
<inline: true>
^ CheckRememberedInTrampoline
]
{ #category : #'debug support' }
CogObjectRepresentationForSpur >> checkValidDerivedObjectReference: bodyAddress [
^(objectMemory heapMapAtWord: (self pointerForOop: bodyAddress - objectMemory baseHeaderSize)) ~= 0
]
{ #category : #'debug support' }
CogObjectRepresentationForSpur >> checkValidOopReference: anOop [
^(objectMemory isImmediate: anOop)
or: [(objectMemory heapMapAtWord: (self pointerForOop: anOop)) ~= 0]
]
{ #category : #'garbage collection' }
CogObjectRepresentationForSpur >> couldBeDerivedObject: bodyAddress [
^self oop: bodyAddress - objectMemory baseHeaderSize isGreaterThanOrEqualTo: objectMemory getMemoryMap startOfObjectMemory
]
{ #category : #'garbage collection' }
CogObjectRepresentationForSpur >> couldBeObject: literal [
^(objectMemory isNonImmediate: literal)
and: [self oop: literal isGreaterThanOrEqualTo: objectMemory getMemoryMap startOfObjectMemory]
]
{ #category : #'bytecode generator support' }
CogObjectRepresentationForSpur >> createsArraysInline [
"Answer if the object representation allocates arrays inline. By
default answer false. Better code can be generated when creating
arrays inline if values are /not/ flushed to the stack."
^true
]
{ #category : #'bytecode generator support' }
CogObjectRepresentationForSpur >> createsClosuresInline [
"Answer if the object representation allocates closures inline. By
default answer false. Better code can be generated when creating
closures inline if copied values are /not/ flushed to the stack."
^true
]
{ #category : #initialization }
CogObjectRepresentationForSpur >> ensureNoForwardedLiteralsIn: aMethodObj [
"Ensure there are no forwarded literals in the argument."
<doNotGenerate>
objectMemory ensureNoForwardedLiteralsIn: aMethodObj
]
{ #category : #'sista support' }
CogObjectRepresentationForSpur >> freeCounters: theCounters [
<var: #theCounters type: #usqInt>
<inline: true>
<option: #SistaCogit>
theCounters ~= 0 ifTrue:
[objectMemory freeObject: theCounters - objectMemory baseHeaderSize]
]
{ #category : #initialization }
CogObjectRepresentationForSpur >> genActiveContextTrampolineLarge: isLarge inBlock: isInBlock called: aString [
<var: #aString type: #'char *'>
"Create a trampoline to answer the active context that will
answer it if a frame is already married, and create it otherwise.
Assume numArgs is in SendNumArgsReg and ClassReg is free."
| startAddress |
startAddress := cogit methodZoneBase.
cogit zeroOpcodeIndex.
self genGetActiveContextLarge: isLarge inBlock: isInBlock.
cogit outputInstructionsForGeneratedRuntimeAt: startAddress.
cogit recordGeneratedRunTime: aString address: startAddress.
cogit recordRunTimeObjectReferences.
^startAddress
]
{ #category : #'primitive generators' }
CogObjectRepresentationForSpur >> genAllocExternalAddressValue: valueReg into: resultReg scratchReg: scratch1 scratchReg: scratch2 [
<returnTypeC: #'AbstractInstruction *'>
| allocSize newExternalAddressHeader jumpFail |
allocSize := objectMemory baseHeaderSize + objectMemory wordSize.
newExternalAddressHeader := objectMemory
headerForSlots: 1
format: objectMemory firstByteFormat
classIndex: objectMemory classExternalAddressIndex.
cogit MoveAw: objectMemory freeStartAddress R: resultReg.
cogit LoadEffectiveAddressMw: allocSize r: resultReg R: scratch1.
cogit CmpCq: objectMemory getScavengeThreshold R: scratch1.
jumpFail := cogit JumpAboveOrEqual: 0.
cogit MoveR: scratch1 Aw: objectMemory freeStartAddress.
self genStoreHeader: newExternalAddressHeader intoNewInstance: resultReg using: scratch1.
cogit MoveR: valueReg Mw: objectMemory baseHeaderSize r: resultReg.
^jumpFail
]
{ #category : #'primitive generators' }
CogObjectRepresentationForSpur >> genAllocFloatValue: dpreg into: resultReg scratchReg: scratch1 scratchReg: scratch2 [
<returnTypeC: #'AbstractInstruction *'>
| allocSize newFloatHeader jumpFail |
<var: #jumpFail type: #'AbstractInstruction *'>
allocSize := objectMemory baseHeaderSize + (objectMemory sizeof: #double).
newFloatHeader := objectMemory
headerForSlots: (self sizeof: #double) / objectMemory wordSize
format: objectMemory firstLongFormat
classIndex: ClassFloatCompactIndex.
cogit MoveAw: objectMemory freeStartAddress R: resultReg.
cogit LoadEffectiveAddressMw: allocSize r: resultReg R: scratch1.
cogit CmpCq: objectMemory getScavengeThreshold R: scratch1.
jumpFail := cogit JumpAboveOrEqual: 0.
cogit MoveR: scratch1 Aw: objectMemory freeStartAddress.
self genStoreHeader: newFloatHeader intoNewInstance: resultReg using: scratch1.
cogit MoveRd: dpreg M64: objectMemory baseHeaderSize r: resultReg.
^jumpFail
]
{ #category : #'primitive generators' }
CogObjectRepresentationForSpur >> genBoxedOrSmallFloat: floatOopReg scratchReg: scratchReg into: destReg [
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpImmediate type: #'AbstractInstruction *'>
<var: #jumpFail type: #'AbstractInstruction *'>
<var: #jumpFailClass type: #'AbstractInstruction *'>
<var: #jumpMerge type: #'AbstractInstruction *'>
| jumpImmediate jumpFail jumpFailClass jumpMerge |
"Must be pointer"
jumpImmediate := self genJumpImmediate: floatOopReg.
"Compare with the boxed float clas."
self genGetCompactClassIndexNonImmOf: floatOopReg into: scratchReg.
self genCmpClassFloatCompactIndexR: scratchReg.
jumpFailClass := cogit JumpNonZero: 0.
"Fetch the double from the boxed float."
self genGetDoubleValueOf: floatOopReg into: destReg.
jumpMerge := cogit Jump: 0.
jumpImmediate jmpTarget: (jumpFailClass jmpTarget: (jumpFail := cogit Jump: 0)).
jumpMerge jmpTarget: cogit Label.
^ jumpFail
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genCheckRememberedBitOf: objReg scratch: scratchReg [
"Check the remembered bit of the object in objReg; answer the jump taken if the bit is already set.
Only need to fetch the byte containing it, which reduces the size of the mask constant."
| rememberedBitByteOffset mask |
rememberedBitByteOffset := cogit backEnd isBigEndian
ifTrue: [objectMemory baseHeaderSize - 1 - (objectMemory rememberedBitShift // 8)]
ifFalse:[objectMemory rememberedBitShift // 8].
mask := 1 << (objectMemory rememberedBitShift \\ 8).
cogit MoveMb: rememberedBitByteOffset r: objReg R: scratchReg.
cogit TstCq: mask R: scratchReg.
^cogit JumpNonZero: 0
]
{ #category : #'in-line cacheing' }
CogObjectRepresentationForSpur >> genCmpClassIndex: classIndex R: reg [
"It is safe to use a short comparison for the known classes; these will not
change with become, etc... But it's probably not safe to assume the hash of
some other class won't change over time, so to be sure of generating the
same size code over time, use a long comparison for unknown classes."
classIndex < objectMemory classTablePageSize
ifTrue: [cogit CmpCq: classIndex R: TempReg]
ifFalse: [cogit CmpCw: classIndex R: TempReg]
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genConvertCharacterToCodeInReg: reg [
cogit LogicalShiftRightCq: objectMemory numTagBits R: reg.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genConvertIntegerToCharacterInReg: reg [
cogit
LogicalShiftLeftCq: objectMemory numTagBits R: reg;
AddCq: objectMemory characterTag R: reg.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genConvertSmallIntegerToCharacterInReg: reg [
self subclassResponsibility
]
{ #category : #'bytecode generator support' }
CogObjectRepresentationForSpur >> genCreateFullClosureInIndex: anIndex numCopied: numCopied ignoreContext: ignoreContext contextNumArgs: contextNumArgs large: contextIsLarge inBlock: contextIsBlock intoRegister: destinationRegister [
"Create a full closure with the given values."
<var: #skip type: #'AbstractInstruction *'>
| numSlots byteSize header skip numArgs compiledBlock |
compiledBlock := cogit getLiteral: anIndex.
numArgs := coInterpreter argumentCountOf: compiledBlock.
"First get thisContext into destinationRegister and thence in ClassReg."
ignoreContext
ifTrue: [ cogit genMoveNilR: ClassReg ]
ifFalse: [
cogit voidReceiverResultRegContainsSelf.
self
genGetActiveContextNumArgs: contextNumArgs
large: contextIsLarge
inBlock: contextIsBlock.
cogit MoveR: ReceiverResultReg R: ClassReg ].
numSlots := FullClosureFirstCopiedValueIndex + numCopied.
byteSize := objectMemory smallObjectBytesForSlots: numSlots.
self assert: ClassFullBlockClosureCompactIndex ~= 0.
header := objectMemory
headerForSlots: numSlots
format: objectMemory indexablePointersFormat
classIndex: ClassFullBlockClosureCompactIndex.
cogit MoveAw: objectMemory freeStartAddress R: destinationRegister.
self
genStoreHeader: header
intoNewInstance: destinationRegister
using: TempReg.
cogit
LoadEffectiveAddressMw: byteSize r: destinationRegister R: TempReg;
MoveR: TempReg Aw: objectMemory freeStartAddress;
CmpCq: objectMemory getScavengeThreshold R: TempReg.
skip := cogit JumpBelow: 0.
cogit CallRT: ceScheduleScavengeTrampoline.
skip jmpTarget: cogit Label.
cogit
MoveR: ClassReg
Mw: FullClosureOuterContextIndex * objectMemory bytesPerOop
+ objectMemory baseHeaderSize
r: destinationRegister;
genMoveConstant: compiledBlock R: TempReg;
MoveR: TempReg
Mw: FullClosureCompiledBlockIndex * objectMemory bytesPerOop
+ objectMemory baseHeaderSize
r: destinationRegister;
MoveCq: (objectMemory integerObjectOf: numArgs) R: TempReg;
MoveR: TempReg
Mw: FullClosureNumArgsIndex * objectMemory bytesPerOop
+ objectMemory baseHeaderSize
r: destinationRegister.
^ 0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genEnsureObjInRegNotForwarded: reg scratchReg: scratch [
"Make sure that the object in reg is not forwarded. This routine assumes the object will
never be forwarded to an immediate, as it is used to unforward literal variables (associations).
Use the fact that isForwardedObjectClassIndexPun is a power of two to save an instruction."
| loop ok |
<var: #ok type: #'AbstractInstruction *'>
<var: #loop type: #'AbstractInstruction *'>
self assert: reg ~= scratch.
loop := cogit Label.
"notionally
self genGetClassIndexOfNonImm: reg into: scratch.
cogit CmpCq: objectMemory isForwardedObjectClassIndexPun R: TempReg.
but the following is an instruction shorter:"
cogit MoveMw: 0 r: reg R: scratch.
cogit
AndCq: objectMemory classIndexMask - objectMemory isForwardedObjectClassIndexPun
R: scratch.
ok := cogit JumpNonZero: 0.
self genLoadSlot: 0 sourceReg: reg destReg: reg.
cogit Jump: loop.
ok jmpTarget: cogit Label.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch [
^ self
genEnsureOopInRegNotForwarded: reg
scratchReg: scratch
jumpBackTo: cogit Label "label is just before the forwarder check"
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch ifForwarder: fwdJumpTarget ifNotForwarder: nonFwdJumpTargetOrZero [
"Make sure that the oop in reg is not forwarded.
Use the fact that isForwardedObjectClassIndexPun is a power of two to save an instruction."
| imm ok finished |
self assert: reg ~= scratch.
imm := self genJumpImmediate: reg.
"notionally
self genGetClassIndexOfNonImm: reg into: scratch.
cogit CmpCq: objectMemory isForwardedObjectClassIndexPun R: TempReg.
but the following is an instruction shorter:"
cogit MoveMw: 0 r: reg R: scratch.
cogit
AndCq: objectMemory classIndexMask - objectMemory isForwardedObjectClassIndexPun
R: scratch.
ok := cogit JumpNonZero: 0.
self genLoadSlot: 0 sourceReg: reg destReg: reg.
cogit Jump: fwdJumpTarget.
finished := nonFwdJumpTargetOrZero asUnsignedInteger = 0
ifTrue: [cogit Label]
ifFalse: [nonFwdJumpTargetOrZero].
imm jmpTarget: (ok jmpTarget: finished).
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch jumpBackTo: instruction [
<var: #instruction type: #'AbstractInstruction *'>
<inline: true>
^ self
genEnsureOopInRegNotForwarded: reg
scratchReg: scratch
ifForwarder: instruction
ifNotForwarder: 0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch updatingMw: offset r: baseReg [
"Make sure that the oop in reg is not forwarded, and the field reg[offset] is updated
if the object in reg is forwarded. Use the fact that isForwardedObjectClassIndexPun is
a power of two to save an instruction."
| loop imm ok |
<var: #ok type: #'AbstractInstruction *'>
<var: #imm type: #'AbstractInstruction *'>
<var: #loop type: #'AbstractInstruction *'>
self assert: (reg ~= scratch and: [baseReg ~= scratch]).
loop := cogit Label.
imm := self genJumpImmediate: reg.
"notionally
self genGetClassIndexOfNonImm: reg into: scratch.
cogit CmpCq: objectMemory isForwardedObjectClassIndexPun R: TempReg.
but the following is an instruction shorter:"
cogit MoveMw: 0 r: reg R: scratch.
cogit
AndCq: objectMemory classIndexMask - objectMemory isForwardedObjectClassIndexPun
R: scratch.
ok := cogit JumpNonZero: 0.
self genLoadSlot: 0 sourceReg: reg destReg: reg.
cogit MoveR: reg Mw: offset r: baseReg.
cogit Jump: loop.
ok jmpTarget: (imm jmpTarget: cogit Label).
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch updatingSlot: index in: objReg [
"Make sure that the oop in reg is not forwarded, updating the slot in objReg with the value."
| loop imm ok |
<var: #ok type: #'AbstractInstruction *'>
<var: #imm type: #'AbstractInstruction *'>
<var: #loop type: #'AbstractInstruction *'>
"Open-code
self genEnsureOopInRegNotForwarded: reg
scratchReg: scratch
updatingMw: index * objectMemory wordSize + objectMemory baseHeaderSize
r: objReg.
to avoid calling the store check unless the receiver is forwarded."
self assert: (reg ~= scratch and: [objReg ~= scratch]).
loop := cogit Label.
imm := self genJumpImmediate: reg.
"notionally
self genGetClassIndexOfNonImm: reg into: scratch.
cogit CmpCq: objectMemory isForwardedObjectClassIndexPun R: TempReg.
but the following is an instruction shorter:"
cogit MoveMw: 0 r: reg R: scratch.
cogit
AndCq: objectMemory classIndexMask - objectMemory isForwardedObjectClassIndexPun
R: scratch.
ok := cogit JumpNonZero: 0.
self genLoadSlot: 0 sourceReg: reg destReg: reg.
cogit MoveR: reg Mw: index * objectMemory wordSize + objectMemory baseHeaderSize r: objReg.
"Check that we're meeting the contract of ceStoreCheckContextReceiverTrampoline."
self assert: (reg = Arg0Reg and: [scratch = TempReg and: [objReg = ReceiverResultReg]]).
cogit CallRT: ceStoreCheckContextReceiverTrampoline.
cogit Jump: loop.
ok jmpTarget: (imm jmpTarget: cogit Label).
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genFetchIndexRegister: indexReg from: tableObj into: destReg [
"indexReg contains the 1-relative index of an element in tableObj."
self subclassResponsibility
]
{ #category : #initialization }
CogObjectRepresentationForSpur >> genGetActiveContextLarge: isLarge inBlock: isInBlock [
"Create a trampoline to answer the active context that will
answer it if a frame is already married, and create it otherwise.
Assume numArgs is in SendNumArgsReg and ClassReg is free."
| header slotSize jumpSingle loopHead jumpNeedScavenge continuation exit |
<var: #jumpNeedScavenge type: #'AbstractInstruction *'>
<var: #continuation type: #'AbstractInstruction *'>
<var: #jumpSingle type: #'AbstractInstruction *'>
<var: #loopHead type: #'AbstractInstruction *'>
<var: #exit type: #'AbstractInstruction *'>
cogit "load the flag; stash it in both TempReg & ClassReg; do the compare (a prime candidated for use of AndCq:R:R:)"
MoveMw: FoxMethod r: FPReg R: ClassReg;
AndCq: MFMethodFlagHasContextFlag R: ClassReg R: TempReg.
jumpSingle := cogit JumpZero: 0. "jump if flag bit not set"
cogit "since the flag bit was set, get the context in the receiver reg and return"
MoveMw: FoxThisContext r: FPReg R: ReceiverResultReg;
RetN: 0.
jumpSingle jmpTarget: cogit Label.
"OK, it doesn't exist; instantiate and initialize it"
"set the hasContext flag; See CoInterpreter class>>initializeFrameIndices"
cogit
OrCq: MFMethodFlagHasContextFlag R: ClassReg;
MoveR: ClassReg Mw: FoxMethod r: FPReg.
"now get the home CogMethod into ClassReg and save for post-instantiation."
isInBlock caseOf: {
[InFullBlock] -> [cogit SubCq: 3 R: ClassReg]. "-3 is -(hasContext+isBlock) flags"
[0] -> [cogit SubCq: 1 R: ClassReg]. "-1 is hasContext flag" }.
"instantiate the context..."
slotSize := isLarge ifTrue: [LargeContextSlots] ifFalse: [SmallContextSlots].
header := objectMemory
headerForSlots: slotSize
format: objectMemory indexablePointersFormat
classIndex: ClassMethodContextCompactIndex.
self flag: #endianness.
cogit MoveAw: objectMemory freeStartAddress R: ReceiverResultReg.
self genStoreHeader: header intoNewInstance: ReceiverResultReg using: TempReg.
cogit
MoveR: ReceiverResultReg R: TempReg;
AddCq: (objectMemory smallObjectBytesForSlots: slotSize) R: TempReg;
MoveR: TempReg Aw: objectMemory freeStartAddress;
CmpCq: objectMemory getScavengeThreshold R: TempReg.
jumpNeedScavenge := cogit JumpAboveOrEqual: 0.
"Now initialize the fields of the context. See CoInterpreter>>marryFrame:SP:copyTemps:"
"sender gets frame pointer as a SmallInteger"
continuation :=
cogit MoveR: FPReg R: TempReg.
self genSetSmallIntegerTagsIn: TempReg.
cogit MoveR: TempReg Mw: objectMemory baseHeaderSize + (SenderIndex * objectMemory bytesPerOop) r: ReceiverResultReg.
"pc gets frame caller as a SmallInteger"
cogit MoveMw: FoxSavedFP r: FPReg R: TempReg.
self genSetSmallIntegerTagsIn: TempReg.
cogit MoveR: TempReg Mw: objectMemory baseHeaderSize + (InstructionPointerIndex * objectMemory bytesPerOop) r: ReceiverResultReg.
"Set the method field, freeing up ClassReg again, and frame's context field,"
cogit
MoveMw: (cogit offset: CogMethod of: #methodObject) r: ClassReg R: TempReg;
MoveR: TempReg Mw: objectMemory baseHeaderSize + (MethodIndex * objectMemory wordSize) r: ReceiverResultReg;
MoveR: ReceiverResultReg Mw: FoxThisContext r: FPReg.
"Now compute stack pointer; this is stackPointer (- 1 for return pc if a CISC) - framePointer - wordSize (1 each for saved pc, method, context, receiver) + 1 (1-relative) + numArgs"
"TPR note - the code here is actually doing
context stackPointer := ((((fp - sp) / wordSize) - [3|4]) + num args) asSmallInteger"
cogit
MoveR: FPReg R: TempReg;
SubR: SPReg R: TempReg;
LogicalShiftRightCq: self log2BytesPerWord R: TempReg;
SubCq: (cogit backEnd hasLinkRegister ifTrue: [3] ifFalse: [4]) R: TempReg;
AddR: SendNumArgsReg R: TempReg.
self genConvertIntegerToSmallIntegerInReg: TempReg.
cogit MoveR: TempReg Mw: objectMemory baseHeaderSize + (StackPointerIndex * objectMemory bytesPerOop) r: ReceiverResultReg.
"Set closureOrNil to either the stacked receiver or nil"
isInBlock > 0
ifTrue:
[cogit
MoveR: SendNumArgsReg R: TempReg;
AddCq: 2 R: TempReg; "+2 for saved fp and saved pc"
MoveXwr: TempReg R: FPReg R: TempReg]
ifFalse:
[cogit genMoveNilR: TempReg].
cogit MoveR: TempReg Mw: objectMemory baseHeaderSize + (ClosureIndex * objectMemory bytesPerOop) r: ReceiverResultReg.
"Set the receiver"
cogit
MoveMw: FoxMFReceiver r: FPReg R: TempReg;
MoveR: TempReg Mw: objectMemory baseHeaderSize + (ReceiverIndex * objectMemory bytesPerOop) r: ReceiverResultReg.
"Now copy the arguments. This is tricky because of the shortage of registers,. ClassReg ranges
from 1 to numArgs (SendNumArgsReg), and from ReceiverIndex + 1 to ReceiverIndex + numArgs.
1 to: numArgs do:
[:i|
temp := longAt(FPReg + ((SendNumArgs - i + 2) * wordSize)). +2 for saved pc and savedfp
longAtput(FPReg + FoxMFReceiver + (i * wordSize), temp)]"
"TPR note: this is a prime candidate for passing off to the backend to do at least faintly optimal code"
cogit MoveCq: 1 R: ClassReg.
loopHead := cogit CmpR: SendNumArgsReg R: ClassReg.
exit := cogit JumpGreater: 0.
cogit
MoveR: SendNumArgsReg R: TempReg;
SubR: ClassReg R: TempReg;
AddCq: 2 R: TempReg; "+2 for saved fp and saved pc"
MoveXwr: TempReg R: FPReg R: TempReg;
AddCq: ReceiverIndex + (objectMemory baseHeaderSize / objectMemory wordSize) R: ClassReg; "Now convert ClassReg from frame index to context index"
MoveR: TempReg Xwr: ClassReg R: ReceiverResultReg;
SubCq: ReceiverIndex + (objectMemory baseHeaderSize / objectMemory wordSize) - 1 R: ClassReg; "convert back adding 1 ;-)"
Jump: loopHead.
exit jmpTarget: cogit Label.
"Finally nil or copy the non-argument temps.
ClassReg := FPReg + FoxMFReceiver.
SendNumArgsReg := SendNumArgsReg+ReceiverIndex.
[ClassReg := ClassReg - wordSize.
backEnd hasLinkRegister
ifTrue: [ClassReg > SPReg]
ifFalse: [ClassReg >= SPReg]] whileTrue:
[receiver[SendNumArgsReg] := *ClassReg.
SendNumArgsReg := SendNumArgsReg + 1]]"
coInterpreter marryFrameCopiesTemps ifFalse:
[cogit MoveCq: objectMemory nilObject R: TempReg].
cogit
MoveR: FPReg R: ClassReg;
AddCq: FoxMFReceiver R: ClassReg;
AddCq: ReceiverIndex + 1 + (objectMemory baseHeaderSize / objectMemory wordSize) R: SendNumArgsReg.
loopHead :=
cogit SubCq: objectMemory wordSize R: ClassReg.
cogit CmpR: SPReg R: ClassReg.
"If on a CISC there's a retpc for the trampoline call on top of stack; if on a RISC there isn't."
exit := cogit backEnd hasLinkRegister
ifTrue: [cogit JumpBelow: 0]
ifFalse: [cogit JumpBelowOrEqual: 0].
coInterpreter marryFrameCopiesTemps ifTrue:
[cogit MoveMw: 0 r: ClassReg R: TempReg].
cogit
MoveR: TempReg Xwr: SendNumArgsReg R: ReceiverResultReg;
AddCq: 1 R: SendNumArgsReg;
Jump: loopHead.
exit jmpTarget: cogit Label.
cogit RetN: 0.
jumpNeedScavenge jmpTarget: cogit Label.
cogit backEnd saveAndRestoreLinkRegAround:
[cogit
CallRT: ceScheduleScavengeTrampoline
registersToBeSavedMask: (cogit registerMaskFor: ReceiverResultReg and: SendNumArgsReg and: ClassReg)].
cogit Jump: continuation.
^0
]
{ #category : #'bytecode generator support' }
CogObjectRepresentationForSpur >> genGetActiveContextNumArgs: numArgs large: isLargeContext inBlock: isInBlock [
"Get the active context into ReceiverResultReg, creating it if necessary."
| routine |
routine := isLargeContext
ifFalse: [isInBlock caseOf: {
[0] -> [ceSmallActiveContextInMethodTrampoline].
[InFullBlock] -> [ceSmallActiveContextInFullBlockTrampoline] }]
ifTrue: [isInBlock caseOf: {
[0] -> [ceLargeActiveContextInMethodTrampoline].
[InFullBlock] -> [ceLargeActiveContextInFullBlockTrampoline] }].
cogit
MoveCq: numArgs R: SendNumArgsReg;
CallRT: routine.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetBits: mask ofFormatByteOf: sourceReg into: destReg [
self flag: #endianness.
cogit MoveMb: 3 r: sourceReg R: destReg.
cogit AndCq: mask R: destReg. "formatReg := self formatOfHeader: destReg"
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetClassIndexOfNonImm: sourceReg into: destReg [
"Fetch the instance's class index into destReg."
cogit MoveMw: 0 r: sourceReg R: destReg.
cogit AndCq: objectMemory classIndexMask R: destReg.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetClassObjectOf: instReg into: destReg scratchReg: scratchReg instRegIsReceiver: instRegIsReceiver [
"Fetch the instance's class into destReg. If the instance is not the receiver and is forwarded, follow forwarding."
| jumpIsImm jumpNotForwarded loop |
<var: #jumpIsImm type: #'AbstractInstruction *'>
<var: #jumpNotForwarded type: #'AbstractInstruction *'>
<var: #loop type: #'AbstractInstruction *'>
(instReg = destReg or: [instReg = scratchReg or: [destReg = scratchReg]]) ifTrue:
[^BadRegisterSet].
loop := cogit MoveR: instReg R: scratchReg.
cogit AndCq: objectMemory tagMask R: scratchReg.
jumpIsImm := cogit JumpNonZero: 0.
self flag: #endianness.
"Get least significant half of header word in destReg"
cogit MoveMw: 0 r: instReg R: scratchReg.
"mask off class index"
cogit AndCq: objectMemory classIndexMask R: scratchReg.
instRegIsReceiver ifFalse:
["if it is forwarded..."
cogit CmpCq: objectMemory isForwardedObjectClassIndexPun R: scratchReg.
jumpNotForwarded := cogit JumpNonZero: 0.
"...follow the forwarding pointer and loop to fetch its classIndex"
cogit MoveMw: objectMemory baseHeaderSize r: instReg R: instReg.
cogit Jump: loop.
jumpNotForwarded jmpTarget: cogit Label].
jumpIsImm jmpTarget:
(cogit MoveR: scratchReg R: destReg).
scratchReg = TempReg
ifTrue:
[cogit PushR: instReg.
self genGetClassObjectOfClassIndex: destReg into: instReg scratchReg: TempReg.
cogit MoveR: instReg R: destReg.
cogit PopR: instReg]
ifFalse:
[self genGetClassObjectOfClassIndex: destReg into: scratchReg scratchReg: TempReg.
cogit MoveR: scratchReg R: destReg].
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetClassObjectOfClassIndex: instReg into: destReg scratchReg: scratchReg [
"Fetch the class object whose index is in instReg into destReg.
It is non-obvious, but the Cogit assumes loading a class does not involve
a runtime call, so do not call classAtIndex:"
self assert: instReg ~= destReg.
self assert: instReg ~= scratchReg.
self assert: destReg ~= scratchReg.
cogit
MoveR: instReg R: scratchReg;
LogicalShiftRightCq: objectMemory classTableMajorIndexShift R: scratchReg;
LogicalShiftLeftCq: objectMemory shiftForWord R: scratchReg.
self assert: (self shouldAnnotateObjectReference: objectMemory classTableRootObj) not.
(cogit backEnd isWithinMwOffsetRange: objectMemory classTableRootObj + objectMemory baseHeaderSize)
ifTrue: [cogit MoveMw: objectMemory classTableRootObj + objectMemory baseHeaderSize r: scratchReg R: destReg]
ifFalse: [cogit
AddCq: objectMemory classTableRootObj R: scratchReg;
MoveMw: objectMemory baseHeaderSize r: scratchReg R: destReg].
cogit
MoveR: instReg R: scratchReg;
AndCq: objectMemory classTableMinorIndexMask R: scratchReg;
AddCq: objectMemory baseHeaderSize >> objectMemory shiftForWord R: scratchReg;
MoveXwr: scratchReg R: destReg R: destReg.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetClassTagOf: instReg into: destReg scratchReg: scratchReg [
^self genGetInlineCacheClassTagFrom: instReg into: destReg forEntry: true
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetCompactClassIndexNonImmOf: instReg into: destReg [
"Fetch the instance's class index into destReg."
^self genGetClassIndexOfNonImm: instReg into: destReg
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetDoubleValueOf: srcReg into: destFPReg [
cogit MoveM64: objectMemory baseHeaderSize r: srcReg Rd: destFPReg.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetFormatOf: srcReg into: destReg [
"Get the format field of the object in srcReg into destReg.
srcReg may equal destReg."
^self genGetBits: objectMemory formatMask ofFormatByteOf: srcReg into: destReg
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentationForSpur >> genGetFormatOf: sourceReg into: destReg leastSignificantHalfOfBaseHeaderIntoScratch: scratchRegOrNone [
"Get the format of the object in sourceReg into destReg. If scratchRegOrNone
is not NoReg, load at least the least significant 32-bits (64-bits in 64-bits) of the
header word, which contains the format, into scratchRegOrNone."
scratchRegOrNone = NoReg
ifTrue:
[self flag: #endianness.
cogit MoveMb: 3 r: sourceReg R: destReg]
ifFalse:
[cogit MoveMw: 0 r: sourceReg R: destReg.
cogit MoveR: destReg R: scratchRegOrNone. "destReg := (at least) least significant half of self baseHeader: receiver"
cogit LogicalShiftRightCq: objectMemory formatShift R: destReg].
cogit AndCq: objectMemory formatMask R: destReg. "formatReg := self formatOfHeader: destReg"
^0
]
{ #category : #'inline primitive support' }
CogObjectRepresentationForSpur >> genGetInstanceOfByteClass: classObj into: destReg initializingIf: initializeInstance numBytes: numBytes [
"Create an instance of classObj and assign it to destReg, initializing the instance
if initializeInstance is true with 0 This is for inline primitives.
Assume there is sufficient space in new space to complete the operation."
| classIndex numSlots byteFormat |
classIndex := objectMemory rawHashBitsOf: classObj.
self flag: #duplication. "Duplicated byteFormatForNumBytes: and numSlotsForBytes:, might be worth adding api"
numSlots := numBytes + (objectMemory wordSize - 1) // objectMemory wordSize.
byteFormat := objectMemory firstByteFormat + (8 - numBytes bitAnd: objectMemory wordSize - 1).
self assert: classIndex ~= 0.
self genGetUninitializedInstanceWithClassIndex: classIndex numSlots: numSlots format: byteFormat into: destReg.
(initializeInstance and: [numBytes > 0]) ifTrue:
[self genStoreValue: 0 instance: destReg numSlots: numSlots].
^0
]
{ #category : #'inline primitive support' }
CogObjectRepresentationForSpur >> genGetInstanceOfPointerClass: classObj into: destReg initializingIf: initializeInstance numVariableSlots: varSlots [
"Create an instance of classObj and assign it to destReg, initializing the instance
if initializeInstance is true with nil This is for inline primitives.
Assume there is sufficient space in new space to complete the operation."
| classIndex classFormat totalNumSlots fixedSlots |
classIndex := objectMemory rawHashBitsOf: classObj.
classFormat := objectMemory formatOfClass: classObj.
fixedSlots := objectMemory fixedFieldsOfClassFormat: classFormat.
totalNumSlots := varSlots + fixedSlots.
self assert: classIndex ~= 0.
self genGetUninitializedInstanceWithClassIndex: classIndex numSlots: totalNumSlots format: (objectMemory instSpecOfClassFormat: classFormat) into: destReg.
(initializeInstance and: [totalNumSlots > 0]) ifTrue:
[self genStoreValue: objectMemory nilObject instance: destReg numSlots: totalNumSlots].
^0