fixed the stack growth issue when manipulating the instruction pointer by intruducing a new primitive method MethodContext>>goto:

This commit is contained in:
hyunghwan.chung
2016-05-18 11:10:54 +00:00
parent 717ffcbdd9
commit 38ccdbed9d
5 changed files with 91 additions and 97 deletions

View File

@ -34,10 +34,15 @@
^self.ip + 1
}
#method goto: anInteger
{
<primitive: #_context_goto>
self primitiveFailed. ## TODO: need to make this a hard failure?
}
#method pc: anInteger
{
self.ip := anInteger.
"self.sp := self.sp - 1." "whould this always work??? "
}
#method sp
@ -184,11 +189,18 @@
## --------------------------------------------------
## If VM is built with STIX_USE_PROCSTK
## --------------------------------------------------
| pc |
| pc sp |
pc := thisContext pcplus1.
(self value) ifFalse: [ ^nil "^self" ].
(self value) ifFalse: [ ^nil ].
aBlock value.
thisContext pc: pc.
## the pc: method leaves thisContext and pc in the stack after
## having changes the instruction poointer.
## as a result, the stack keeps growing. the goto method
## clears thisContext and pc off the stack unlike normal methods.
##thisContext pc: pc.
thisContext goto: pc.
## --------------------------------------------------
}
@ -202,8 +214,8 @@
## --------------------------------------------------
| pc |
pc := thisContext pcplus1.
(self value) ifFalse: [ ^nil "^self" ].
thisContext pc: pc.
(self value) ifFalse: [ ^nil ].
thisContext goto: pc.
## --------------------------------------------------
}
@ -247,7 +259,7 @@
pc := thisContext pcplus1.
(self value) ifTrue: [ ^nil "^self" ].
aBlock value.
thisContext pc: pc.
thisContext goto: pc.
## --------------------------------------------------
}
@ -262,7 +274,7 @@
| pc |
pc := thisContext pcplus1.
(self value) ifTrue: [ ^nil "^self" ].
thisContext pc: pc.
thisContext goto: pc.
## --------------------------------------------------
}

View File

@ -104,10 +104,11 @@
#method critical: aBlock
{
'CRITICAL....11' dump.
## TODO: implement this
"
self wait.
'CRITICAL....22' dump.
^aBlock ensure: [ self signal ]
"
}
## ==================================================================

View File

@ -48,7 +48,8 @@
#method(#class) main
{
## test critical region
## THIS CRASHES VM. PLEASE CHECK. CRASHES WHEN REPETITION IS 1000
|t1 t2 s1 s2 s3|
'START OF MAIN' dump.
@ -57,13 +58,13 @@
s2 := Semaphore new.
t1 := [
1000 timesRepeat: ['BLOCK #1' dump].
10000 timesRepeat: ['BLOCK #1' dump].
##s2 critical: [
## 10 timesRepeat: ['BLOCK #1' dump ]
##]
] newProcess.
t2 := [
1000 timesRepeat: ['BLOCK #2' dump].
10000 timesRepeat: ['BLOCK #2' dump].
##s2 critical: [
## 10 timesRepeat: ['BLOCK #2' dump. ]
##].
@ -78,6 +79,18 @@
'END OF MAIN' dump.
"
|s1|
s1 := Semaphore new.
s1 signal.
'XXXXXXXXXXXXXXXX' dump.
s1 wait.
"
"
| v1 |
'START OF MAIN' dump.