--- a/src/JavaVM.st Mon Aug 13 22:13:19 2012 +0000
+++ b/src/JavaVM.st Tue Aug 14 00:38:58 2012 +0000
@@ -50,11 +50,19 @@
ZipLastModTimesCache ZipInflaters JavaPrivilegedAccessQuery
ClassRegistry SystemClassLoader ExtClassLoader StartupTime
FinalizationEnabled FinalizationLobby ParkUnparkSemaphores
- threadInterrupts EagerResolvingEnabled OldspaceIncreased'
+ threadInterrupts EagerResolvingEnabled OldspaceIncreased
+ PerfCounters'
poolDictionaries:'JavaConstants'
category:'Languages-Java-Support'
!
+Object subclass:#Performance
+ instanceVariableNames:'vm'
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:JavaVM
+!
+
Object subclass:#Reflection
instanceVariableNames:'vm constantPoolMapping javaClasses javaArrayClasses
javaMethodsPerMethod returnNilIfMissing realMethods'
@@ -1071,7 +1079,7 @@
"
!
-performance
+performance1
"
JAVA::BenchMark new loopmark
JAVA::BenchMark new logicmark
@@ -1084,35 +1092,34 @@
"
"
- caffmark loopmark logicmark sievemark methodmark stringmark float image graphic dialog newstringmark neweststringmark
+ caffmark loopmark logicmark sievemark methodmark stringmark float image graphic dialog newstringmark neweststringmark
linux:
P6/233 No JIT 84 87 90 40 22 17 10
- 103 133 142 137 28 73 109 167 18 140
+ 103 133 142 137 28 73 109 167 18 140
P6/233 JIT 479 2459 393 649 28 21 12
P6/233 JIT 473 1805 3046 439 986 28 21 12
- 533 1808 3382 613 1003 25 105 143 1
- 668 3330 3644 740
- 793 4116 3731 1243 1365 120 103 79 2
- 914 4480 4061 2290 68 106 158 19 34
- 941 4607 4149 1238 2434 75 101 152 18 32
- 591 164
- 1087 1836 800 110 35
- 1102 4592 4270 1844 2381 841 109 169 21 35
- 1177 4608 4309 1810 2432 895 532 182 20 35
+ 533 1808 3382 613 1003 25 105 143 1
+ 668 3330 3644 740
+ 793 4116 3731 1243 1365 120 103 79 2
+ 914 4480 4061 2290 68 106 158 19 34
+ 941 4607 4149 1238 2434 75 101 152 18 32
+ 591 164
+ 1087 1836 800 110 35
+ 1102 4592 4270 1844 2381 841 109 169 21 35
+ 1177 4608 4309 1810 2432 895 532 182 20 35
w95
P5/200 JIT 90 95 90 95 686 18 60 54 7
- 428 1657 2385 684 957 21 61 62 9
- 541 2886 2589 823 976 18 62 55 7
- 583 3062 2635 842 861 223 65 57 8
- 616 3075 2438 1081 1324 218 64 54 8
- 718 3138 2755 1085 1200 816 63 48 9 7
-
- caffmark loopmark logicmark sievemark methodmark stringmark float image graphic dialog newstringmark neweststringmark
+ 428 1657 2385 684 957 21 61 62 9
+ 541 2886 2589 823 976 18 62 55 7
+ 583 3062 2635 842 861 223 65 57 8
+ 616 3075 2438 1081 1324 218 64 54 8
+ 718 3138 2755 1085 1200 816 63 48 9 7
+
+ caffmark loopmark logicmark sievemark methodmark stringmark float image graphic dialog newstringmark neweststringmark
"
-
!
performance2
@@ -1923,6 +1930,7 @@
ObjectMemory addDependent: self.
StartupTime := OperatingSystem getOSTime.
FinalizationLobby startFinalizationProcessAt: 5.
+ PerfCounters := Performance for: self.
"
@@ -1934,7 +1942,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 (format): / 24-07-2012 / 15:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 14-08-2012 / 00:41:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
initializeVMIfNoEventThreadRunning
@@ -2332,6 +2340,13 @@
"Created: / 8.1.1999 / 17:06:52 / cg"
!
+performance
+ "Return an object keeping Java performance counters"
+ ^ PerfCounters
+
+ "Modified: / 14-08-2012 / 00:39:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
reflection
^ Reflection.
@@ -4435,11 +4450,13 @@
[ stream := aBlock value ] on:OpenError do:[:ex|
(ex errorCode) == (OperatingSystem errorNumberFor:#EMFILE) ifTrue:[
"Worst case, try to cleanup"
+ Logger log: 'Maximum number of open files reached, forcing finalization...' severity: #warn facility: #JVM.
[
FinalizationLobby finalizeNow.
Delay waitForSeconds: 5. "/Give Java finalization thread a chance to clean up
ObjectMemory garbageCollect.
retry := true.
+ PerfCounters printOpenExternalStreamsOn: Stderr.
] on: Error do:[:ex|
Logger log: 'Failed to force finalization: ', ex description severity: #error facility: #JVM
].
@@ -18819,6 +18836,194 @@
"Modified: / 10.12.1998 / 19:36:59 / cg"
! !
+!JavaVM::Performance class methodsFor:'documentation'!
+
+documentation
+"
+ A helper class to keep performance counters for JavaVM
+
+ [author:]
+ Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ [instance variables:]
+
+ [class variables:]
+
+ [see also:]
+
+"
+! !
+
+!JavaVM::Performance class methodsFor:'instance creation'!
+
+for: aJavaVM
+
+ ^self new setVM: aJavaVM.
+
+ "Created: / 21-12-2010 / 19:42:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaVM::Performance methodsFor:'initialization'!
+
+setVM: aJavaVM
+
+ "Now, aJavaVM == JavaVM (i.e, the class JavaVM
+ itself, not its instance)"
+
+ vm := aJavaVM
+
+ "Created: / 21-12-2010 / 19:44:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaVM::Performance methodsFor:'orinting-streams'!
+
+printOpenExternalStream: stream number: index on: output
+ "Print info about given external stream to output. Return true,
+ if the instance is executor, false otherwise"
+
+ | executor |
+
+ executor := ((3 to: stream class instSize) allSatisfy:[:index|
+ index == 6 or:[index == 7 or:[(stream instVarAt: index) isNil]]
+ ]).
+
+ '%-4d %-30s %-15s %s' printf:{
+ index .
+ stream class name.
+ executor ifTrue:['(executor)'] ifFalse:[(self printOpenExternalStreamIdentificationOf: stream)].
+ executor ifTrue:[''] ifFalse:[stream isFileStream ifTrue:[stream pathName ? '??? no pathName ???'] ifFalse:['']]
+ } on: output.
+
+ ^ executor
+
+ "
+ JavaVM::Performance new printOpenExternalStreams
+ "
+
+ "Created: / 14-08-2012 / 01:02:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+printOpenExternalStreamIdentificationOf:stream
+ | zc oft |
+
+ (oft := Smalltalk at:#'JavaVM:OpenFileTable') notNil ifTrue:[
+ | idx |
+ idx := oft identityIndexOf: stream.
+ idx ~~ 0 ifTrue:[
+ ^ 'VM OFT[' ,idx printString, ']'.
+ ].
+ ].
+ (zc := Smalltalk at:#'JavaVM:ZipCache') notNil ifTrue:[
+ | idx |
+ idx := zc identityIndexOf: stream.
+ idx ~~ 0 ifTrue:[
+ ^ 'VM ZC[' ,idx printString, ']'.
+ ]
+ ].
+
+ ((Smalltalk at:#'Java:SourceCache') ? #()) do:[:each|
+ each == stream ifTrue:[
+ ^ 'Java SC'
+ ].
+ ].
+
+ ((Smalltalk at:#'JavaClassReader:JavaArchiveCache') ? #()) do:[:each|
+ (each instVarAt:1 "named: #file") == stream ifTrue:[
+ ^ 'JCR JAC'
+ ].
+ ].
+
+ ((Smalltalk at:#'Java:SourceArchiveCache') ? #()) do:[:each|
+ (each instVarAt:1 "named: #file") == stream ifTrue:[
+ ^ 'Java SAC'
+ ].
+ ].
+
+ ^''
+
+ "Created: / 14-08-2012 / 01:17:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+printOpenExternalStreams
+ ^self printOpenExternalStreamsOn: Transcript
+
+ "Created: / 14-08-2012 / 01:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+printOpenExternalStreamsOn: aStream
+
+ | nOpenStreams nExecutors |
+
+ aStream nextPutLine: '=== JavaVM open external stream statistics ==='.
+ aStream nextPutLine: Timestamp now printString.
+
+ nOpenStreams := 0.
+ nExecutors := 0.
+ ExternalStream allSubInstancesDo:[:each|
+ each isOpen ifTrue:[
+ nOpenStreams := nOpenStreams + 1.
+ (self printOpenExternalStream: each number: nOpenStreams on: aStream) ifTrue:[
+ nExecutors := nExecutors + 1
+ ].
+ aStream cr.
+ ]
+ ].
+ aStream cr.
+ aStream nextPutLine:
+ ('SUMMARY: open=%1, executors=%4, java.io=%2, java.util.zip=%3'
+ bindWith: nOpenStreams
+ with: (((Smalltalk at:#'JavaVM:OpenFileTable') ? #()) inject:0 into:[:a :s|a + (s notNil ifTrue:[1] ifFalse:[0])])
+ with: (((Smalltalk at:#'JavaVM:ZipCache') ? #()) inject:0 into:[:a :s|a + (s notNil ifTrue:[1] ifFalse:[0])])
+ with: nExecutors
+ ).
+
+ aStream nextPutLine: '=============================================='.
+ aStream nextPutLine: ''
+
+ "
+ JavaVM::Performance new printOpenExternalStreams
+ "
+
+ "Created: / 14-08-2012 / 00:48:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaVM::Performance methodsFor:'printing-counters'!
+
+printCounters
+
+ self printCountersOn: Transcript
+
+ "Created: / 14-08-2012 / 00:43:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+printCountersOn: aStream
+
+ aStream nextPutLine: '=== JavaVM performance statistics ============'.
+ aStream nextPutLine: Timestamp now printString.
+ aStream nextPutLine: '=============================================='.
+ aStream nextPutLine: ''
+
+ "Created: / 14-08-2012 / 00:43:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaVM::Reflection class methodsFor:'documentation'!
+
+documentation
+"
+ A helper class to deal with Java reflection
+
+ [author:]
+ Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ [instance variables:]
+
+ [class variables:]
+
+ [see also:]
+
+"
+! !
+
!JavaVM::Reflection class methodsFor:'instance creation'!
for: aJavaVM