--- a/JavaVM.st Fri Aug 16 19:52:36 2013 +0200
+++ b/JavaVM.st Fri Sep 06 02:45:44 2013 +0200
@@ -1391,7 +1391,7 @@
JavaPrivilegedAccessQuery := QuerySignal new.
JavaPrivilegedAccessQuery defaultAnswer: false.
AssertionsEnabled := true.
- ClassRegistry := JavaClassRegistry new.
+ self initializeClassRegistry.
FinalizationEnabled := true.
EagerResolvingEnabled := false.
@@ -1405,7 +1405,7 @@
"Modified: / 02-12-1998 / 23:02:22 / cg"
"Modified: / 09-10-2011 / 20:29:10 / Marcel Hlopko <hlopik@gmail.com>"
"Modified: / 08-12-2011 / 21:06:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 17-08-2012 / 11:16:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-09-2013 / 00:50:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
initializeAdditionalJavaProtocol
@@ -1558,6 +1558,16 @@
"Created: / 06-09-2012 / 11:18:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+initializeClassRegistry
+ ClassRegistry isNil ifTrue:[
+ ClassRegistry := JavaClassRegistry new.
+ ] ifFalse:[
+ ClassRegistry flush.
+ ]
+
+ "Created: / 03-09-2013 / 00:50:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
initializeJavaResources
self initializeMonitorTable.
self initializePrimitiveClasses.
@@ -1947,6 +1957,11 @@
ZipEntryCache := OrderedCollection new.
ZipInflaters := OrderedCollection new.
FinalizationLobby := JavaFinalizationRegistry new.
+ JavaVMData classVarNames do:[:nm |
+ nm first == $_ ifTrue:[
+ Smalltalk at: (JavaVMData globalKeyForClassVar:nm) put: nil.
+ ]
+ ].
self initializeNatives.
"/ force re-resolving;
@@ -2005,7 +2020,7 @@
"Modified: / 15-10-2010 / 15:27:45 / Jan Kurs <kurs.jan@post.cz>"
"Modified: / 24-02-2012 / 13:59:29 / Marcel Hlopko <hlopik@gmail.com>"
"Modified: / 24-02-2012 / 14:37:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 20-02-2013 / 00:13:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-08-2013 / 11:49:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
initializeVMIfNoEventThreadRunning
@@ -2493,7 +2508,7 @@
is resolved"
aClass methodDictionary do:[:mthd|
- (mthd isJavaMethod and:[mthd isResolved not]) ifTrue:[
+ (mthd isJavaMethod and:[mthd isNative not and:[mthd isResolved not]]) ifTrue:[
"Stdout nextPutAll:'Flushing code for ' , mthd printString; cr."
mthd code: nil.
mthd checked: false.
@@ -2544,47 +2559,45 @@
classForName: className definedBy: classLoader
"load class from registry - load using given classLoader if not nil"
- | result |
+ | result binaryName |
+ binaryName := className asSlashedJavaClassName.
result := self
- classForName: className asSlashedJavaClassName
+ classForName: binaryName
definedBy: classLoader
ifAbsentPut: [
| class classLoaderEnsured |
- self assert: (className includes: $.) not.
+ self assert: (binaryName includes: $.) not.
self booted ifFalse: [
"class loaders allowed after vm boot, until then, only primordial"
- class := self usePrimordialCLToLoadClassNamed: className.
+ class := self usePrimordialCLToLoadClassNamed: binaryName.
self assert:(class notNil)
- message:'Couldnt load class ' , className , ' while booting Java VM'.
+ message:'Couldnt load class ' , binaryName , ' while booting Java VM'.
class.
] ifTrue: [
self assert:(self booted)
- message:'Java VM is not booted and we are not using primordial class loader to load: '
- , className.
+ message:'Java VM is not booted and we are not using primordial class loader to load: ' , className.
(Java release bootClassPathIncludesClassNamed: className) ifTrue: [
"we will use primordial class loader for classes in rt.jar etc"
- class := self usePrimordialCLToLoadClassNamed: className.
+ class := self usePrimordialCLToLoadClassNamed: binaryName.
self assert:(class notNil)
- message:'Class ' , className
- , ' is supposed to be in boot classpath, but we couldnt load it'.
+ message:'Class ' , binaryName , ' is supposed to be in boot classpath, but we couldnt load it'.
class.
] ifFalse: [
- (Java release extDirsIncludesClassNamed: className) ifTrue: [
- class := self useExtCLToLoadClassNamed: className.
+ (Java release extDirsIncludesClassNamed: binaryName) ifTrue: [
+ class := self useExtCLToLoadClassNamed: binaryName.
self assert:(class notNil)
- message:'Class ' , className
- , ' is supposed to be in java.ext,dirs, but we couldnt load it'.
+ message:'Class ' , binaryName , ' is supposed to be in java.ext,dirs, but we couldnt load it'.
class.
] ifFalse: [
"at this point, nil classLoader means use system class loader,
in other words, at this point, we shouldnt use primordial cl at all"
classLoader isNil ifTrue: [
self assert:(self systemClassLoader notNil)
- message:'We needed system class loader, but its not loaded yet'.
+ message:'We needed system class loader, but its not loaded yet'.
classLoaderEnsured := self systemClassLoader
] ifFalse: [ classLoaderEnsured := classLoader ].
class := self useUserDefinedCL: classLoaderEnsured
- toLoadClassNamed: className.
+ toLoadClassNamed: binaryName.
class isNil ifTrue: [
Logger
log: 'Even ' , classLoader printString , ' was not able to load class '
@@ -2606,8 +2619,8 @@
^ result.
"Created: / 21-10-2011 / 12:01:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 30-10-2011 / 13:54:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-11-2011 / 16:49:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 07-05-2013 / 12:27:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
classForName: className definedBy: classLoader ifAbsentPut: aBlock
@@ -3103,7 +3116,7 @@
!JavaVM class methodsFor:'helpers'!
canCast: s to: t
- "Helper for _CHECKCAST:_:"
+ "Helper for _CHECKCAST(_R):_:/_INSTANCEOF(_R):_:"
| sc tc |
@@ -3403,8 +3416,7 @@
throwException: aJavaException
<resource: #skipInDebuggersWalkBack>
- | con jMsg msg exClass senderContext srchCon handlerContext handlerPC method pc hPC handler |
-
+ | con jMsg msg exClass srchCon handlerContext handlerPC method pc hPC handler |
ExceptionTrace ifTrue: [
| tmpMessage |
tmpMessage := aJavaException instVarNamed: 'detailMessage'.
@@ -3432,26 +3444,33 @@
"/
"/ search stack for a javaContext which handles that exception
"/
- srchCon := senderContext := thisContext sender.
+
+
+ srchCon := thisContext.
[ handlerContext isNil and: [ srchCon notNil ] ] whileTrue: [
- (srchCon isJavaContext) ifTrue: [
- method := srchCon method.
- pc := srchCon pc.
- (hPC := method handlerFor: aJavaException at: pc) notNil ifTrue: [
- handlerPC := hPC.
- handlerContext := srchCon
- ].
- ] ifFalse:[
- srchCon isHandleContext ifTrue:[
- handler := srchCon receiver
- handlerForSignal: aJavaException class context: srchCon originator:senderContext.
- handler notNil ifTrue:[
- "We have found a Smalltalk handler for Java exception here"
- handlerContext := srchCon.
- ]
+ srchCon := srchCon findSpecialHandle:true raise:false.
+ srchCon notNil ifTrue:[
+ (srchCon isJavaContext) ifTrue: [
+ method := srchCon method.
+ method exceptionTable notNil ifTrue:[
+ self assert: srchCon isHandleContext.
+ ].
+ pc := srchCon pc.
+ (hPC := method handlerFor: aJavaException at: pc) notNil ifTrue: [
+ handlerPC := hPC.
+ handlerContext := srchCon
+ ].
+ ] ifFalse:[
+ srchCon isHandleContext ifTrue:[
+ handler := srchCon receiver
+ handlerForSignal: aJavaException class context: srchCon originator:thisContext sender.
+ handler notNil ifTrue:[
+ "We have found a Smalltalk handler for Java exception here"
+ handlerContext := srchCon.
+ ]
+ ].
].
].
- srchCon := srchCon sender.
].
handlerContext isNil ifTrue: [
"/
@@ -3469,9 +3488,9 @@
"/ for our convenience: skip ST contexts
"/ (i.e. the handler or debugger will see the javaContext first )
- con := senderContext.
+ con := thisContext sender.
[ con isNil or: [ con isJavaContext ] ] whileFalse: [ con := con sender ].
- con isNil ifTrue: [ con := senderContext ].
+ con isNil ifTrue: [ con := thisContext sender ].
JavaUnhandledExceptionError
raiseWith: aJavaException
errorString: msg
@@ -3513,7 +3532,8 @@
"Created: / 07-01-1998 / 15:28:22 / cg"
"Modified: / 24-12-1999 / 02:33:25 / cg"
"Modified: / 01-12-2011 / 18:32:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 18-03-2012 / 21:47:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-05-2013 / 01:59:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+
!
throwExceptionClassName: aJavaExceptionClassName withMessage: someMessage
@@ -3681,6 +3701,12 @@
"Created: / 30-11-2011 / 12:23:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
+throwInterruptedIOException: message
+ ^ self throwExceptionClassName: 'java.io.InterruptedIOException' withMessage:message
+
+ "Created: / 15-08-2013 / 21:36:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
throwInvocationTargetException: message target: target
| exClass ex |
@@ -3724,17 +3750,11 @@
!
throwNullPointerException
- NullPointerExceptionDebug == true ifTrue:[
- self halt:'Null Pointer exception'.
- ].
-
- ^ self
- throwExceptionClassName:'java.lang.NullPointerException'
- withMessage:'null pointer'
+ self throwNullPointerException:'null pointer'
"Created: / 09-01-1998 / 02:26:08 / cg"
"Modified: / 28-01-1998 / 02:30:09 / cg"
- "Modified: / 13-08-2011 / 01:10:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-04-2013 / 21:18:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
throwNullPointerException:message
@@ -3984,7 +4004,11 @@
monitorEnter:someObject in:aJavaContext
| thisProcess wasBlocked lockWordOrJavaMonitor |
- self assert:(aJavaContext isNil or:[ aJavaContext isJavaContext ]).
+ "/ Following assesrtion no longer holds as native methods are not
+ "/ JavaMethods (they are smalltalk trampolines) and thus their
+ "/ activation does not create Java context
+
+ "/ self assert:(aJavaContext isNil or:[ aJavaContext isJavaContext ]).
someObject isNil ifTrue:[
self throwNullPointerException.
self breakPoint:#mh.
@@ -3993,9 +4017,10 @@
thisProcess := Processor activeProcess.
MonitorTrace ifTrue:[
Logger
- log:('MONENTER: entering monitor for %1 in %2'
+ log:('MONENTER: entering monitor for %1 in %2 thread %3'
bindWith:(self monitorFriendlyPrintStringOf:someObject)
- with:thisProcess name)
+ with: aJavaContext selector
+ with: thisProcess id)
severity:#debug
facility:#JVM.
].
@@ -4019,13 +4044,16 @@
MonitorTrace ifTrue:[
Logger
- log:'MONENTER: monitor entered in ' , thisProcess name
+ log:('MONENTER: monitor entered for %1 in %2 thread %3'
+ bindWith:(self monitorFriendlyPrintStringOf:someObject)
+ with: aJavaContext selector
+ with: thisProcess id)
severity:#debug
facility:#JVM.
].
"Created: / 08-11-2011 / 15:15:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 27-08-2012 / 11:49:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 10-03-2013 / 01:49:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
monitorExit: someObject in: aJavaContext
@@ -4039,9 +4067,10 @@
thisProcess := Processor activeProcess.
MonitorTrace ifTrue: [
Logger
- log: ('MONEXIT: leaving monitor for %1 in %2'
+ log: ('MONEXIT: leaving monitor for %1 in %2 thread %3'
bindWith: (self monitorFriendlyPrintStringOf: someObject)
- with: thisProcess name) , thisProcess name
+ with: aJavaContext selector
+ with: thisProcess id)
severity: #info
facility: #JVM.
].
@@ -4053,7 +4082,10 @@
MonitorTrace ifTrue: [
Logger
- log: 'MONEXIT: monitor left in ' , thisProcess name
+ log: ('MONEXIT: monitor left for %1 in %2 thread %3'
+ bindWith: (self monitorFriendlyPrintStringOf: someObject)
+ with: aJavaContext selector
+ with: thisProcess id)
severity: #info
facility: #JVM.
].
@@ -4115,7 +4147,8 @@
thisProcess := Processor activeProcess.
wasBlocked := OperatingSystem blockInterrupts.
- receiver := aJavaContext acquiredMonitors.
+ "/self assert: aJavaContext method isSynchronized.
+ receiver := aJavaContext receiver.
receiver notNil ifTrue:[
lockWord := receiver getJavaLockWord.
] ifFalse:[
@@ -4341,7 +4374,7 @@
log: ('[trace id %3] Entering monitor %1 owned by thread: %2'
bindWith: (self monitorFriendlyPrintStringOf: obj)
with: aProcess id
- with: MonitorTraceId)
+ with: '???' "MonitorTraceId")
severity: #trace
facility: #JVM
originator: self
@@ -4465,7 +4498,7 @@
log: ('[trace id %3] leaving monitor %1 owned by thread: %2 '
bindWith: (self monitorFriendlyPrintStringOf: obj)
with: aProcess name
- with: (self enteredMonitorsOfProcess: aProcess) last second)
+ with: '???' "(self enteredMonitorsOfProcess: aProcess) last second")
severity: #trace
facility: #JVM
originator: self
@@ -4669,7 +4702,7 @@
version_HG
- ^ '§Changeset: <not expanded> §'
+ ^ 'Changeset: <not expanded> '
! !
!JavaVM class methodsFor:'queries'!
@@ -4680,7 +4713,7 @@
"/Slightly faster variant of the code below
^SystemClassLoader notNil and:[
- jVM := JavaVM classNamed: 'sun.misc.VM'.
+ jVM := JavaVM classNamed: 'sun.misc.VM' definedBy: nil.
jVM notNil and: [ (jVM instVarNamed: #booted) == 1 ]
].
@@ -4692,7 +4725,7 @@
"Created: / 08-08-2011 / 10:04:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-11-2011 / 22:08:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 04-12-2011 / 10:32:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 02-05-2013 / 01:22:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaVM class methodsFor:'threads'!
@@ -4817,6 +4850,29 @@
!JavaVM class methodsFor:'vm support'!
+_AALOAD: arr _: index
+ "Called from the VM (___aaload()) for unhandled cases"
+
+ arr basicAt: index + 1
+
+ "Created: / 29-04-2013 / 21:22:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+_AASTORE: arr _: val _: index
+ "Called from the VM (___aastore()) for unhandled cases"
+
+ (val notNil and:[arr isJavaArray])"false" ifTrue:[
+ (self canCast: val class to: arr class javaComponentClass) ifFalse: [
+ self throwArrayStoreException: 'Incompatible types'.
+ ^ nil "Not reached"
+ ].
+ ].
+ arr basicAt: index + 1 put: val
+
+ "Created: / 29-04-2013 / 21:22:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+
+!
+
_ANEWARRAY:cls _:size
"Returns a new array of elements of type class."
@@ -4848,6 +4904,8 @@
<resource: #skipInDebuggersWalkBack>
+ | message |
+
aJavaException isNil ifTrue:[
self halt:'cannot happen'
].
@@ -4858,37 +4916,30 @@
ATHROW at the end of finally block to pass execution to another handler.
We don't want to do so, in case we're manually invoking finally blocks.
Hence following hack: we teleport back to handler caller"
- aJavaException class == JavaContext::FinallyToken ifTrue:[
+ aJavaException class == JavaContext finallyTokenClass ifTrue:[
aJavaException pass.
self halt:'Should never be reached'.
].
+ "Another kludge: ECJ compiler throws java.lang.Error in case
+ there's an unresolved compilation problem. We want to open debugger
+ in this case tp be more Smalltalk-like - so translate such exception
+ to JavaUnresolvedCompilationError"
+ aJavaException class name == #'java/lang/Error' ifTrue:[
+ message := aJavaException getMessage.
+ (message startsWith: 'Unresolved compilation problem:') ifTrue:[
+ JavaUnresolvedCompilationError newException
+ messageText: (message copyFrom: 'Unresolved compilation problem:' size + 1) trimSeparators;
+ proceedable: true;
+ raiseSignal.
+ ^thisContext sender return
+ ]
+ ].
+
self throwException:aJavaException
"Created: / 08-01-1999 / 14:15:36 / cg"
"Modified: / 08-11-2011 / 16:32:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 09-04-2012 / 21:00:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-_CHECKCAST2: object _: classRef
- "Called by the VM (java bytecode interpreter) for unhandled cases.
- Unlike in _CHECKCAST:_: the second parameter is a class reference,
- not the class itself!! Will wanish!!"
-
- | class |
-
- classRef isJavaRef ifTrue: [ class := classRef resolve ] ifFalse: [
- self error: '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 (comment): / 09-10-2012 / 11:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-04-2013 / 23:49:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
_CHECKCAST: object _: class
@@ -4900,6 +4951,7 @@
into GC. See ___checkcast() VM function
"
+ object isNil ifTrue: [ ^ object ].
(self canCast: object class to: class) ifFalse: [
self throwClassCastException.
^ nil "Not reached"
@@ -4911,6 +4963,26 @@
"Modified: / 09-10-2012 / 11:53:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+_CHECKCAST_R: object _: classRef
+ "Called by the VM (java bytecode interpreter) for unhandled cases.
+ Unlike in _CHECKCAST:_: the second parameter is a class reference,
+ not the class itself!! Called by JIT-compiled code."
+
+ | class |
+
+ object isNil ifTrue: [ ^ object ].
+ class := classRef resolve.
+ (self canCast: object class to: class) ifFalse: [
+ self throwClassCastException.
+ ^ nil
+ ].
+
+ ^ object.
+
+ "Created: / 19-05-2011 / 10:12:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified (comment): / 09-10-2012 / 11:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
_D2I:op1
|v|
@@ -5049,13 +5121,12 @@
_INSTANCEOF_R: object _: classRef
"Called by the VM (java bytecode interpreter) for unhandled cases.
Unlike _INSTANCEOF:_: the second parameter is a class reference,
- not the class itself!! Will wanish!!"
-
+ not the class itself!! Called by JIT-compiled code."
+
| class |
- classRef isJavaRef ifFalse: [self error: 'expected only classRefs - maybe I was wrong'].
- class := classRef resolve.
object isNil ifTrue: [ ^ 0 ].
+ class := classRef resolve.
^ (self canCast: object class to: class) ifTrue: [ 1 ] ifFalse: [ 0 ].
"Created: / 15-10-2012 / 21:51:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -5101,7 +5172,7 @@
reference (StringRef or ClassRef"
^ref isJavaClassRef ifTrue:[
- self javaClassObjectForClass: ref resolve
+ self javaClassObjectForClass: (ref resolve: false)
] ifFalse:[
ref resolve
]
@@ -6365,9 +6436,6 @@
of java.lang.Class should be first created by myself
(by sending #javaClassObjectForClass:)"
- (javaClasses at: aJavaClassObject ifAbsent: [ 123 ])
- == (JavaVM classNamed: 'stx/libjava/tests/junir/JUnit3Tests')
- ifTrue: [ self breakPoint: #jv ].
^ javaClasses at: aJavaClassObject
ifAbsent: [
vm internalError: 'No class associated with given java.lang.Class!!'.
@@ -6378,8 +6446,8 @@
].
"Created: / 28-01-2011 / 15:22:39 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 05-02-2011 / 20:26:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 21-10-2011 / 13:41:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 02-05-2013 / 01:16:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
javaClassObjectArrayForClasses: classes
@@ -6650,15 +6718,15 @@
!JavaVM class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libjava/JavaVM.st,v 1.190 2013-05-07 13:42:51 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libjava/JavaVM.st,v 1.192 2013-09-06 00:41:27 vrany Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libjava/JavaVM.st,v 1.190 2013-05-07 13:42:51 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libjava/JavaVM.st,v 1.192 2013-09-06 00:41:27 vrany Exp $'
!
version_SVN
- ^ '§Id§'
+ ^ 'Id'
! !