--- a/src/JavaVM.st Wed Oct 19 16:18:27 2011 +0000
+++ b/src/JavaVM.st Wed Oct 19 18:05:11 2011 +0000
@@ -2501,73 +2501,74 @@
!JavaVM class methodsFor:'helpers'!
-canCast: s to: t
+canCast: s to: t
"Helper for _CHECKCAST:_:"
- | sc tc |
-
- "Not specified in JVM spec, sigh"
- s isJavaPrimitiveType ifTrue:[
+
+ | sc tc |
+
+
+ "Not specified in JVM spec, sigh"
+ s isJavaPrimitiveType ifTrue: [
"FIXME"
- ^s == t
- ].
- "
- Java VM Spec, 3rd edition, p 280:
-
- The following rules are used to determine whether an objectref that is not
- null can be cast to the resolved type: if S is the class of the object
- referred to by objectref and T is the resolved class, array, or interface type,
- checkcast determines whether objectref can be cast to type T as follows:
-
- - If S is an ordinary (nonarray) class, then:
- - If T is a class type, then S must be the same class as T, or a subclass
- of T.
- - If T is an interface type, then S must implement interface T.
- "
- (s isJavaArrayClass not and:[s isInterface not]) ifTrue:
- [^s includesBehavior: t].
-
- "
- - If S is an interface type, then:
- - If T is a class type, then T must be Object.
- - If T is an interface type, then T must be the same interface as S or a
- superinterface of S.
- "
- s isInterface ifTrue:
- [^t isInterface not
- ifTrue: [t == (self classForName:'java.lang.Object')]
- ifFalse:[s includesBehavior: t]].
- "
- - If S is a class representing the array type SC[], that is, an array of com-
- ponents of type SC , then:
+ ^ s == t
+ ].
+ "
+ Java VM Spec, 3rd edition, p 280:
+
+ The following rules are used to determine whether an objectref that is not
+ null can be cast to the resolved type: if S is the class of the object
+ referred to by objectref and T is the resolved class, array, or interface type,
+ checkcast determines whether objectref can be cast to type T as follows:
+
+ - If S is an ordinary (nonarray) class, then:
+ - If T is a class type, then S must be the same class as T, or a subclass
+ of T.
+ - If T is an interface type, then S must implement interface T.
+ "
+ (s isJavaArrayClass not and: [ s isInterface not ]) ifTrue: [
+ (s includesBehavior: t) ifTrue: [^true] ifFalse:[self breakPoint:#mh].
+ ].
+ "
+ - If S is an interface type, then:
+ - If T is a class type, then T must be Object.
+ - If T is an interface type, then T must be the same interface as S or a
+ superinterface of S.
+ "
+ s isInterface ifTrue: [
+ ^ t isInterface not
+ ifTrue: [ t == (self classForName: 'java.lang.Object') ]
+ ifFalse: [ s includesBehavior: t ]
+ ].
+ "
+ - If S is a class representing the array type SC[], that is, an array of com-
+ ponents of type SC , then:
"
self assert: s isJavaArrayClass description: 'S should be array type'.
sc := s javaComponentClass.
- "
- - If T is a class type, then T must be Object.
- "
- t isJavaClassType ifTrue:
- [^t == (self classForName: 'java.lang.Object')].
- "
- - If T is an array type TC[], that is, an array of components of type TC ,
- then one of the following must be true:
- - TC and SC are the same primitive type.
- - TC and SC are reference types, and type SC can be cast to TC by
- recursive application of these rules.
- "
- t isJavaArrayClass ifTrue:
- [tc := t javaComponentClass.
- ^tc isJavaPrimitiveType
- ifTrue:[tc == sc]
- ifFalse:[self canCast: sc to: tc]].
- "
- - If T is an interface type, T must be one of the interfaces implemented
- by arrays (JLS3 4.10.3).
- "
- ((t name == #'java/lang/Cloneable') or:
- [t name == #'java/lang/Serializable'])
- ifTrue:[^true].
-
- ^false
+ "
+ - If T is a class type, then T must be Object.
+ "
+ t isJavaClassType ifTrue: [ ^ t == (self classForName: 'java.lang.Object') ].
+ "
+ - If T is an array type TC[], that is, an array of components of type TC ,
+ then one of the following must be true:
+ - TC and SC are the same primitive type.
+ - TC and SC are reference types, and type SC can be cast to TC by
+ recursive application of these rules.
+ "
+ t isJavaArrayClass ifTrue: [
+ tc := t javaComponentClass.
+ ^ tc isJavaPrimitiveType
+ ifTrue: [ tc == sc ]
+ ifFalse: [ self canCast: sc to: tc ]
+ ].
+ "
+ - If T is an interface type, T must be one of the interfaces implemented
+ by arrays (JLS3 4.10.3).
+ "
+ ((t name == #'java/lang/Cloneable')
+ or: [ t name == #'java/lang/Serializable' ]) ifTrue: [ ^ true ].
+ ^ false
"Modified: / 09-01-1999 / 00:45:21 / cg"
"Created: / 11-02-2011 / 08:21:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -2615,9 +2616,9 @@
newThread:name
|thread threadClass i|
- threadClass := Java at:'java.lang.Thread'.
-
- thread := (Java at:'java.lang.Thread') basicNew.
+ threadClass := Java javaRegistry at:'java/lang/Thread'.
+
+ thread := (Java javaRegistry at:'java/lang/Thread') basicNew.
thread instVarNamed:'name' put:(Java as_String:name).
thread instVarNamed:'priority' put:(threadClass instVarNamed:'NORM_PRIORITY').
thread instVarNamed:'single_step' put:0.
@@ -2628,7 +2629,7 @@
"/ that on was only temporarily present in JDK1.1.3 (sigh)
"/
(i := thread class instVarOffsetOf:'initial_stack_memory') notNil ifTrue:[
- thread instVarAt:i put:0.
+ thread instVarAt:i put:0.
].
thread instVarNamed:'group' put:(self standardThreadGroup).
^ thread
@@ -2654,7 +2655,7 @@
|standardGroup threadClass|
StandardThreadGroup isNil ifTrue:[
- threadClass := Java at:'java.lang.Thread'.
+ threadClass := Java javaRegistry at:'java/lang/Thread'.
standardGroup := (self classForName:'java.lang.ThreadGroup') new.
standardGroup instVarNamed:'parent' put:nil.
@@ -3051,9 +3052,9 @@
!
throwClassCastException
- ^ self
- throwExceptionClassName:'java.lang.ClassCastException'
- withMessage:'cast failed'
+self breakPoint: #mh.
+ ^ self throwExceptionClassName: 'java.lang.ClassCastException'
+ withMessage: 'cast failed'
"Modified: / 7.1.1998 / 15:25:35 / cg"
"Created: / 8.1.1999 / 18:55:31 / cg"
@@ -6415,15 +6416,15 @@
|exClass exceptionObject list con|
- exClass := Java classNamed:'java.lang.Throwable'.
+ exClass := Java classNamed:'java/lang/Throwable'.
exceptionObject := nativeContext receiver.
"/
"/ debugging only
"/
- (exceptionObject isKindOf:(Java classNamed:'java.lang.Throwable')) ifFalse:[
- self halt
+ (exceptionObject isKindOf:(Java javaRegistry at:'java/lang/Throwable')) ifFalse:[
+ self halt
].
con := thisContext sender.
@@ -6432,24 +6433,24 @@
"/ we are not interrested in all intermediate Exception frames ...
"/
FullExceptionTrace ifFalse:[
- "/ first, skip any JavaVM contexts
- [con receiver == exceptionObject] whileFalse:[
- con := con sender
- ].
- "/ then, all exception-init contexts
- [con receiver == exceptionObject] whileTrue:[
- con := con sender
- ].
+ "/ first, skip any JavaVM contexts
+ [con receiver == exceptionObject] whileFalse:[
+ con := con sender
+ ].
+ "/ then, all exception-init contexts
+ [con receiver == exceptionObject] whileTrue:[
+ con := con sender
+ ].
].
list := OrderedCollection new.
[con notNil] whileTrue:[
- (con isJavaContext) ifTrue:[
- "/ add a copy, in case the context continues with some
- "/ cleanup ...
- list add:con shallowCopy
- ].
- con := con sender
+ (con isJavaContext) ifTrue:[
+ "/ add a copy, in case the context continues with some
+ "/ cleanup ...
+ list add:con shallowCopy
+ ].
+ con := con sender
].
exceptionObject instVarNamed:'backtrace' put:(list asArray).
@@ -7275,7 +7276,7 @@
JavaClassReader."
| jClassLoader jName data offset length inStream newClass jClass |
-
+ self breakPoint: #mh.
jClassLoader := nativeContext receiver.
jName := nativeContext argAt: 1.
data := nativeContext argAt: 2.
@@ -7406,8 +7407,8 @@
_ClassLoader_resolveClass0: nativeContext
"resolve a new class as previously created by defineClass0"
- | jClassLoader jCls cls anyUnresolved |
-
+ | jClassLoader jCls cls anyUnresolved |
+self breakPoint:#mh.
jClassLoader := nativeContext receiver.
jCls := nativeContext argAt: 1.
jCls isNil ifTrue: [
@@ -7422,8 +7423,8 @@
('JavaVM [info]: resolving class ' , cls fullName , ' ...') infoPrintCR.
JavaClassReader classLoaderQuerySignal answer: jClassLoader
do: [
- "correct this so it works with new resolving"
- self breakPoint:#mh.
+ "correct this so it works with new resolving"
+ self breakPoint: #mh.
JavaClassReader resolveClass: cls.
"/ JavaClassReader postLoadActions:true.
@@ -7461,66 +7462,62 @@
"Modified: / 28-01-2011 / 15:28:18 / Marcel Hlopko <hlopik@gmail.com>"
!
-_ClassLoader_resolveClass:nativeContext
+_ClassLoader_resolveClass: nativeContext
"void resolveClass (java.lang.Class)"
-
"resolve a new class as previously created by defineClass0"
-
- |jClassLoader jCls cls loaderStub anyUnresolved|
-
+
+ | jClassLoader jCls cls loaderStub anyUnresolved |
+ self breakPoint: #mh.
jClassLoader := nativeContext receiver.
- jCls := nativeContext argAt:1.
- jCls isNil ifTrue:[
+ jCls := nativeContext argAt: 1.
+ jCls isNil ifTrue: [
self halt.
^ nil
].
-UnimplementedNativeMethodSignal raiseRequest.
+ UnimplementedNativeMethodSignal raiseRequest.
"Modified: / 27.1.2000 / 02:36:01 / cg"
!
-_Class_forName:nativeContext
+_Class_forName: nativeContext
"get a java.lang.Class by name"
-
- |jClassName className cls jClass s m c loader|
-
- jClassName := nativeContext argAt:1.
- className := Java as_ST_String:jClassName.
-
- (s := nativeContext sender) notNil ifTrue:[
- (s isJavaContext) ifTrue:[
- c := s method javaClass.
- loader := c classLoader.
- loader isNil ifTrue:[
-"/ self halt.
- ]
- ]
- ].
-
- JavaClassReader classLoaderQuerySignal answer:loader
- do:[
- cls := Java classForName:className.
- ].
-
+
+ | jClassName className cls jClass s m c loader |
+ self breakPoint: #mh.
+ jClassName := nativeContext argAt: 1.
+ className := Java as_ST_String: jClassName.
+ (s := nativeContext sender) notNil ifTrue: [
+ (s isJavaContext) ifTrue: [
+ c := s method javaClass.
+ loader := c classLoader.
+ loader isNil ifTrue: [
+ "/ self halt.
+ ]
+ ]
+ ].
+ JavaClassReader classLoaderQuerySignal answer: loader
+ do: [ cls := Java classForName: className. ].
+
"/(className startsWith:'sun.awt') ifTrue:[self halt].
"/('classForName: ' , className , ' -> ') print.
"/cls notNil ifTrue:[cls fullName printCR] ifFalse:['nil' printCR].
-
- cls isNil ifTrue:[
- ExceptionTrace ifTrue:[
- ('throwing exception: no such class:' , className) infoPrintCR.
- ].
- ExceptionDebug ifTrue:[
- self halt:'no such class:' , className.
- ].
- self throwClassNotFoundException:className.
- "/ not proceedable
- AbortSignal raise.
- "/ not reached
- ^ self
- ].
-
- ^ self javaClassObjectForClass:cls.
+
+ cls isNil ifTrue: [
+ ExceptionTrace ifTrue: [
+ ('throwing exception: no such class:' , className) infoPrintCR.
+ ].
+ ExceptionDebug ifTrue: [ self halt: 'no such class:' , className. ].
+ self throwClassNotFoundException: className.
+
+ "/ not proceedable
+
+ AbortSignal raise.
+
+ "/ not reached
+
+ ^ self
+ ].
+ ^ self javaClassObjectForClass: cls.
"Modified: / 30.12.1998 / 20:12:53 / cg"
!
@@ -15310,40 +15307,38 @@
| class |
- aJavaClassRef isJavaRef
- ifTrue: [ class := aJavaClassRef resolve ]
- ifFalse: [ self halt: 'I expected classRefs only - maybe I was wrong' ].
- (object isNil or: [ (self canCast: object class to: class) not ])
- ifTrue:
- [ self throwClassCastException.
- ^ false ].
- "
- (self canCast: object class to: class) not
- ifTrue:
- [ self throwClassCastException.
- ^ false ].
- "
+ aJavaClassRef isJavaRef ifTrue: [ class := aJavaClassRef resolve ] ifFalse: [
+ self halt: 'I expected classRefs only - maybe I was wrong'
+ ].
+ (object isNil or: [ (self canCast: object class to: class) not ]) ifTrue: [
+ self breakPoint: #mh.
+ self throwClassCastException.
+ ^ false
+ ].
+
^ true.
"Created: / 19-05-2011 / 10:12:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 13-08-2011 / 01:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-_CHECKCAST:object _: classOrClassRef
+_CHECKCAST: object _: classOrClassRef
"Trampouline for unhandled cases ..."
-
+
| class |
+ self breakPoint: #mh.
class := classOrClassRef javaClass.
-
- "
- Java VM Spec, 3rd edition, p 280:
-
- If objectref is null, the checkcast instruction throws a ClassCastException.
- "
- ("object isNil"false or:[(self canCast: object class to: class) not])
- ifTrue:[self throwClassCastException. ^false].
- ^true
+ "
+ Java VM Spec, 3rd edition, p 280:
+
+ If objectref is null, the checkcast instruction throws a ClassCastException.
+ " "object isNil"
+ (false or: [ (self canCast: object class to: class) not ]) ifTrue: [
+ self throwClassCastException.
+ ^ false
+ ].
+ ^ true
"Created: / 08-01-1999 / 14:53:51 / cg"
"Modified: / 09-01-1999 / 00:45:21 / cg"
@@ -16474,7 +16469,7 @@
(by sending #javaClassObjectForClass:)
"
- (javaClasses at: aJavaClassObject ifAbsent:[123]) == (Java at: 'stx.libjava.tests.junir.JUnit3Tests')
+ (javaClasses at: aJavaClassObject ifAbsent:[123]) == (Java javaRegistry at: 'stx/libjava/tests/junir/JUnit3Tests')
ifTrue:[self breakPoint: #jv].