--- a/JavaContext.st Fri Aug 29 16:03:19 1997 +0000
+++ b/JavaContext.st Mon Jan 05 18:49:32 1998 +0000
@@ -1,5 +1,7 @@
-Object subclass:#JavaContext
- instanceVariableNames:'method class sender stack frameBase pc sp'
+'From Smalltalk/X, Version:3.3.1 on 5-jan-1998 at 2:09:56 pm' !
+
+Context subclass:#JavaContext
+ instanceVariableNames:'exArg byteCode constPool method'
classVariableNames:''
poolDictionaries:''
category:'Java-Support'
@@ -8,25 +10,75 @@
!JavaContext methodsFor:'ST context mimicri'!
-argsAndVars
- |nArgs nVars|
+argAt:n
+ |arg0Index|
+
+ self method isStatic ifTrue:[
+ arg0Index := 0
+ ] ifFalse:[
+ arg0Index := 1
+ ].
+ ^ self at:arg0Index+n
+
+ "Created: / 2.1.1998 / 17:54:13 / cg"
+ "Modified: / 2.1.1998 / 21:39:30 / cg"
+!
- stack isNil ifTrue:[^ #()].
- frameBase isNil ifTrue:[^ #()].
+argAt:n put:value
+ |arg0Index|
- nArgs := method numArgs.
- nVars := method numVars.
+ self method isStatic ifTrue:[
+ arg0Index := 0
+ ] ifFalse:[
+ arg0Index := 1
+ ].
+ ^ super argAt:arg0Index+n put:value
+
+ "Created: / 2.1.1998 / 17:54:34 / cg"
+ "Modified: / 2.1.1998 / 21:35:19 / cg"
+!
+
+args
+ "return an array filled with the arguments of this context"
+
+ |n arg1Index|
- method isStatic ifTrue:[
- (nArgs + nVars) == 0 ifTrue:[
- ^ #()
- ].
- ^ (stack copyFrom:frameBase to:(frameBase + nArgs + nVars - 1)) asArray
+ n := self numArgs.
+ n == 0 ifTrue:[
+ "/ little optimization here - avaoid creating empty containers
+ ^ #()
+ ].
+
+ self method isStatic ifTrue:[
+ arg1Index := 1
+ ] ifFalse:[
+ arg1Index := 2
].
- ^ (stack copyFrom:(frameBase+1) to:(frameBase + nArgs + nVars)) asArray
+ ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:arg1Index.
+
+ "Created: / 2.1.1998 / 17:54:57 / cg"
+ "Modified: / 2.1.1998 / 21:34:44 / cg"
+!
+
+argsAndVars
+ "return an array filled with the arguments and variables of this context"
+
+ |n arg1Index|
- "Created: 1.5.1996 / 17:32:44 / cg"
- "Modified: 12.8.1997 / 22:04:39 / cg"
+ n := self numArgs + self numVars.
+ n == 0 ifTrue:[
+ "/ little optimization here - avaoid creating empty containers
+ ^ #()
+ ].
+ self method isStatic ifTrue:[
+ arg1Index := 1
+ ] ifFalse:[
+ arg1Index := 2
+ ].
+ ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:arg1Index.
+
+ "Created: / 2.1.1998 / 17:55:14 / cg"
+ "Modified: / 2.1.1998 / 21:35:39 / cg"
!
canReturn
@@ -35,237 +87,169 @@
"Created: 1.5.1996 / 15:05:36 / cg"
!
-findNextContextWithSelector:sel1 or:sel2
- sender isNil ifTrue:[^ nil].
- ^ sender findNextContextWithSelector:sel1 or:sel2
-
- "Created: 20.3.1997 / 13:54:01 / cg"
-!
+lineNumber
+ |nr pc|
-hasStackToShow
- ^ true
-!
-
-isBlockContext
- ^ false
-
- "Created: 1.5.1996 / 15:05:26 / cg"
-!
-
-lineNumber
- |nr|
+ pc := self pc.
"/ 'ask line for pc:' print. pc printCR.
pc isNil ifTrue:[" '-> 0 [a]' printCR. " ^0].
- nr := method lineNumberForPC:pc.
+ nr := self method lineNumberForPC:pc.
nr isNil ifTrue:[" '-> 0 [b]' printCR. " ^ 0].
"/ '-> ' print. nr printCR.
^ nr.
- "Created: 1.5.1996 / 15:05:47 / cg"
- "Modified: 12.8.1997 / 02:39:44 / cg"
+ "Created: / 1.5.1996 / 15:05:47 / cg"
+ "Modified: / 4.1.1998 / 23:35:38 / cg"
!
-methodClass
- ^ class
+lineNumberFromMethod
+ |m|
+
+ m := self method.
+ m notNil ifTrue:[
+ ^ m lineNumber
+ ].
+ ^ nil
- "Created: 1.5.1996 / 15:04:17 / cg"
+ "Created: / 4.1.1998 / 23:34:45 / cg"
+ "Modified: / 4.1.1998 / 23:35:55 / cg"
+!
+
+method
+ "the method may be found in the interpreter temps ..."
+
+ (method isMemberOf:JavaMethod) ifTrue:[^ method].
+ ^ super method
+
+ "Created: / 1.5.1996 / 15:03:43 / cg"
+ "Modified: / 2.1.1998 / 21:38:00 / cg"
!
methodHome
^ self
-
- "Created: 1.5.1996 / 15:03:43 / cg"
!
numArgs
- ^ method numArgs
-
- "Created: 1.5.1996 / 15:04:35 / cg"
-!
-
-numVars
- ^ 0
-
- "Created: 1.5.1996 / 15:05:03 / cg"
-!
+ "return the number of args.
+ Redefined since Java keeps the receiver of a non-static method
+ at local slot 0."
-receiver
- method isStatic ifTrue:[
- ^ method javaClass
- ].
- frameBase > stack size ifTrue:[
- ^ nil
- ].
-"/ method displayString printCR.
-"/ frameBase print. ' -> ' print. (stack at:frameBase) printCR.
- ^ stack at:frameBase
-
- "Created: 1.5.1996 / 15:04:03 / cg"
- "Modified: 4.8.1997 / 23:39:01 / cg"
-!
-
-selector
- ^ (method name , method signature) asSymbol "/ signatureName
-
- "Created: 1.5.1996 / 15:03:03 / cg"
-!
-
-stack
- ^ stack
-!
-
-stackFrame
-sp < frameBase ifTrue:[
- 'oops - negative stackFrame' errorPrintCR.
- ^ #()
-].
-stack isNil ifTrue:[^ #()].
+ |n|
-"/ method displayString printCR.
-"/ frameBase print. ' ... ' print. (sp-1) printCR.
-"/ (stack collect:[:e | e class name]) printCR.
-
-"/ method isStatic ifFalse:[
-"/ ^ stack copyFrom:frameBase+1 to:(sp-1)
-"/ ].
- ^ stack copyFrom:frameBase to:(sp-1)
-
- "Modified: 12.8.1997 / 21:55:47 / cg"
-! !
-
-!JavaContext methodsFor:'accessing'!
-
-class:aJavaClass method:aJavaMethod sender:aContext stack:s frameBase:f
- class := aJavaClass.
- method := aJavaMethod.
- sender := aContext.
- stack := s.
- frameBase := f
+ n := super numArgs.
+ self method isStatic ifFalse:[
+ n := n - 1
+ ].
+ ^ n
- "Modified: 1.5.1996 / 17:39:34 / cg"
- "Created: 1.5.1996 / 17:42:27 / cg"
-!
-
-class:aJavaClass method:aJavaMethod sender:aContext stack:s stackPointer:spp frameBase:f
- class := aJavaClass.
- method := aJavaMethod.
- sender := aContext.
- stack := s.
- sp := spp.
- frameBase := f
-
- "Modified: 1.5.1996 / 17:39:34 / cg"
- "Created: 1.5.1996 / 17:42:27 / cg"
-!
-
-method
- ^ method.
-
- "Created: 1.5.1996 / 15:00:23 / cg"
- "Modified: 1.5.1996 / 15:00:47 / cg"
+ "Created: / 2.1.1998 / 22:21:24 / cg"
!
pc
- ^ pc
-!
-
-sender
- ^ sender.
+ lineNr isNil ifTrue:[^ nil].
+ ^ super lineNumber
- "Modified: 1.5.1996 / 15:00:47 / cg"
- "Created: 1.5.1996 / 15:01:18 / cg"
-!
-
-setPC:anInteger
- pc := anInteger
+ "Created: / 4.1.1998 / 23:33:48 / cg"
!
-setPC:pcInteger SP:spInteger
- pc := pcInteger.
- sp := spInteger.
+selector
+ "the selector can be extracted from the method.
+ the method may be found in the interpreter temps ..."
+
+ |s m|
+
+ selector isNil ifTrue:[
+ m := self method.
+ m notNil ifTrue:[
+ ^ m name
+ ]
+ ].
+ ^ super selector
+
+ "Modified: / 30.12.1997 / 17:22:06 / cg"
+ "Created: / 30.12.1997 / 17:23:47 / cg"
!
-setSP:anInteger
- sp := anInteger
-!
+setPC:newPC
+ lineNr := newPC
+
+ "Created: / 5.1.1998 / 00:09:02 / cg"
+! !
+
+!JavaContext methodsFor:'exception handler support'!
-setStack:aCollection
- stack := aCollection
-!
+markForException
+ "set the exception handler flag in the receiver.
+ The JVM needs this to enter an exception handler instead of restarting
+ from the beginning (when the context is restarted).
+ - a highly internal mechanism and not for public use."
-sp
- ^ sp
+%{ /* NOCONTEXT */
+ __INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__JAVA_EX_PEND));
+%}
+
+ "Modified: 13.12.1995 / 19:05:22 / cg"
! !
!JavaContext methodsFor:'printing & storing'!
-printString
- |nm mS recCls rec recClsName rnm|
+receiverPrintString
+ "return a string describing the receiver of the context"
- "/ the methods class
- nm := class fullName.
- (nm startsWith:'java/lang/') ifTrue:[
- nm := class name
- ] ifFalse:[
- (nm startsWith:'java.lang.') ifTrue:[
- nm := class name
- ].
- ].
- "/ to avoid confusion with corresponding smalltalk classes ...
- (Smalltalk includesKey:(nm asSymbol)) ifTrue:[
- nm := class fullName "/ 'JAVA-' , nm
- ].
- nm := nm asString copy replaceAll:$/ by:$..
-
- "/ the receivers class
- rec := self receiver.
- recCls := rec class.
+ |receiverClass receiverClassName newString implementorClass|
- (rec isKindOf:JavaObject) ifFalse:[
- (rec isKindOf:JavaClass) ifTrue:[
- "/ static message
- rnm := recCls name , '[static]'
- ] ifFalse:[
- rnm := '[' , recCls name , ']'
- ]
- ] ifTrue:[
- recClsName := recCls name.
- (Smalltalk includesKey:(recClsName asSymbol)) ifTrue:[
- rnm := recCls fullName "/ 'JAVA-' , recClsName
- ] ifFalse:[
- (recCls fullName startsWith:'java/lang/') ifTrue:[
- rnm := recClsName
- ] ifFalse:[
- rnm := recCls fullName
- ].
- ].
- ].
- rnm := rnm asString copy replaceAll:$/ by:$..
+%{
+ /*
+ * special handling for (invalid) free objects.
+ * these only appear if some primitiveCode does not correctly use SEND macros,
+ * which may lead to sends to free objects. In normal operation, this 'cannot' happen.
+ */
+ if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) {
+ receiverClassName = __MKSTRING("FreeObject");
+ }
+%}.
+ receiverClassName notNil ifTrue:[^ receiverClassName].
- recCls ~~ class ifTrue:[
- ^ rnm , '>>' , nm , '::' , method signatureName
+ receiverClass := receiver class.
+ receiverClassName := receiverClass name.
+ (receiverClass == SmallInteger) ifTrue:[
+ newString := '(' , receiver printString , ') ' , receiverClassName
] ifFalse:[
- ^ rnm , '::' , method signatureName
+ newString := receiverClassName
].
-"/ OLD:
- mS := nm , '::' , method signatureName.
-
- (rnm ~= nm) ifTrue:[
- rnm := rnm asString copy replaceAll:$/ by:$..
- ^ rnm , '>>' , mS
+ "
+ kludge to avoid slow search for containing class
+ "
+ (selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
+ implementorClass := self methodClass.
+ ].
+ implementorClass notNil ifTrue: [
+ (implementorClass ~~ receiverClass) ifTrue: [
+ newString := newString , '>>>',
+ implementorClass name printString
+ ]
+ ] ifFalse:[
+ self searchClass ~~ receiverClass ifTrue:[
+ newString := newString , '>>>' , self searchClass name
+ ].
+"/ "
+"/ kludge for doIt - these unbound methods are not
+"/ found in the classes methodDictionary
+"/ "
+"/ (selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
+"/ newString := newString , '>>>**NONE**'
+"/ ]
].
- ^ mS
+ ^ newString
- "Created: 1.5.1996 / 15:07:43 / cg"
- "Modified: 16.8.1997 / 01:44:50 / cg"
! !
!JavaContext class methodsFor:'documentation'!
version
- ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaContext.st,v 1.17 1997/08/18 10:38:22 cg Exp $'
+ ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaContext.st,v 1.18 1998/01/05 18:47:12 cg Exp $'
! !