--- a/JavaMethodAnalyzer.st Thu Jul 28 09:47:24 2016 +0100
+++ b/JavaMethodAnalyzer.st Fri Jul 29 10:54:57 2016 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1996-2015 by Claus Gittinger
@@ -20,9 +22,12 @@
"
"{ Package: 'stx:libjava' }"
+"{ NameSpace: Smalltalk }"
+
JavaByteCodeProcessorAdapter subclass:#JavaMethodAnalyzer
instanceVariableNames:'fieldsAccessed fieldsRead fieldsWritten staticsAccessed
- staticsRead staticsWritten methodsInvoked refdClasses'
+ staticsRead staticsWritten methodsInvoked refdClasses
+ constantsAccessed'
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Support-Decompiling'
@@ -86,6 +91,30 @@
"Created: / 30-08-2013 / 13:33:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!JavaMethodAnalyzer methodsFor:'enumerating'!
+
+literalsDo: aBlock
+ constantsAccessed do:aBlock.
+ refdClasses do:[:ref |
+ | nameSym |
+
+ nameSym := ref name asSymbolIfInterned.
+ nameSym notNil ifTrue:[
+ aBlock value: nameSym.
+ ].
+ ].
+ methodsInvoked do:[:ref |
+ | selectorSym |
+
+ selectorSym := (ref name , ref descriptor) asSymbolIfInterned.
+ selectorSym notNil ifTrue:[
+ aBlock value: selectorSym
+ ].
+ ]
+
+ "Created: / 29-07-2016 / 09:42:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!JavaMethodAnalyzer methodsFor:'instructions'!
anewarray
@@ -146,6 +175,312 @@
"Created: / 30-08-2013 / 17:05:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+ldc1
+ self ldc: self fetchIndex.
+ "
+ Operation
+
+ Push item from run-time constant pool
+
+ Format
+
+ ldc
+ index
+
+ Forms
+
+ ldc = 18 (0x12)
+
+ Operand Stack
+
+ ... →
+
+ ..., value
+
+ Description
+
+ The index is an unsigned byte that must be a valid index into
+ the run-time constant pool of the current class ([384]§2.6).
+ The run-time constant pool entry at index either must be a
+ run-time constant of type int or float, or a reference to a
+ string literal, or a symbolic reference to a class, method
+ type, or method handle ([385]§5.1).
+
+ If the run-time constant pool entry is a run-time constant of
+ type int or float, the numeric value of that run-time constant
+ is pushed onto the operand stack as an int or float,
+ respectively.
+
+ Otherwise, if the run-time constant pool entry is a reference
+ to an instance of class String representing a string literal
+ ([386]§5.1), then a reference to that instance, value, is
+ pushed onto the operand stack.
+
+ Otherwise, if the run-time constant pool entry is a symbolic
+ reference to a class ([387]§5.1), then the named class is
+ resolved ([388]§5.4.3.1) and a reference to the Class object
+ representing that class, value, is pushed onto the operand
+ stack.
+
+ Otherwise, the run-time constant pool entry must be a symbolic
+ reference to a method type or a method handle ([389]§5.1). The
+ method type or method handle is resolved ([390]§5.4.3.5) and a
+ reference to the resulting instance of
+ java.lang.invoke.MethodType or java.lang.invoke.MethodHandle,
+ value, is pushed onto the operand stack.
+
+ Linking Exceptions
+
+ During resolution of a symbolic reference to a class, any of
+ the exceptions pertaining to class resolution ([391]§5.4.3.1)
+ can be thrown.
+
+ During resolution of a symbolic reference to a method type or
+ method handle, any of the exception pertaining to method type
+ or method handle resolution ([392]§5.4.3.5) can be thrown.
+
+ Notes
+
+ The ldc instruction can only be used to push a value of type
+ float taken from the float value set ([393]§2.3.2) because a
+ constant of type float in the constant pool ([394]§4.4.4) must
+ be taken from the float value set.
+ "
+
+ "Created: / 29-07-2016 / 09:14:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-07-2016 / 10:18:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ldc2
+ self ldc: self fetchIndex2
+
+ "
+ ldc_w
+
+ Operation
+
+ Push item from run-time constant pool (wide index)
+
+ Format
+
+ ldc_w
+ indexbyte1
+ indexbyte2
+
+ Forms
+
+ ldc_w = 19 (0x13)
+
+ Operand Stack
+
+ ... →
+
+ ..., value
+
+ Description
+
+ The unsigned indexbyte1 and indexbyte2 are assembled into an
+ unsigned 16-bit index into the run-time constant pool of the
+ current class ([395]§2.6), where the value of the index is
+ calculated as (indexbyte1 << 8) | indexbyte2. The index must be
+ a valid index into the run-time constant pool of the current
+ class. The run-time constant pool entry at the index either
+ must be a run-time constant of type int or float, or a
+ reference to a string literal, or a symbolic reference to a
+ class, method type, or method handle ([396]§5.1).
+
+ If the run-time constant pool entry is a run-time constant of
+ type int or float, the numeric value of that run-time constant
+ is pushed onto the operand stack as an int or float,
+ respectively.
+
+ Otherwise, if the run-time constant pool entry is a reference
+ to an instance of class String representing a string literal
+ ([397]§5.1), then a reference to that instance, value, is
+ pushed onto the operand stack.
+
+ Otherwise, if the run-time constant pool entry is a symbolic
+ reference to a class ([398]§4.4.1). The named class is resolved
+ ([399]§5.4.3.1) and a reference to the Class object
+ representing that class, value, is pushed onto the operand
+ stack.
+
+ Otherwise, the run-time constant pool entry must be a symbolic
+ reference to a method type or a method handle ([400]§5.1). The
+ method type or method handle is resolved ([401]§5.4.3.5) and a
+ reference to the resulting instance of
+ java.lang.invoke.MethodType or java.lang.invoke.MethodHandle,
+ value, is pushed onto the operand stack.
+
+ Linking Exceptions
+
+ During resolution of the symbolic reference to a class, any of
+ the exceptions pertaining to class resolution ([402]§5.4.3.1)
+ can be thrown.
+
+ During resolution of a symbolic reference to a method type or
+ method handle, any of the exception pertaining to method type
+ or method handle resolution ([403]§5.4.3.5) can be thrown.
+
+ Notes
+
+ The ldc_w instruction is identical to the ldc instruction
+ ([404]§ldc) except for its wider run-time constant pool index.
+
+ The ldc_w instruction can only be used to push a value of type
+ float taken from the float value set ([405]§2.3.2) because a
+ constant of type float in the constant pool ([406]§4.4.4) must
+ be taken from the float value set.
+ "
+
+ "Created: / 29-07-2016 / 09:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-07-2016 / 10:18:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ldc2w
+ constantsAccessed add: (constantPool at: self fetchIndex2).
+
+ "
+ ldc2_w
+
+ Operation
+
+ Push long or double from run-time constant pool (wide index)
+
+ Format
+
+ ldc2_w
+ indexbyte1
+ indexbyte2
+
+ Forms
+
+ ldc2_w = 20 (0x14)
+
+ Operand Stack
+
+ ... →
+
+ ..., value
+
+ Description
+
+ The unsigned indexbyte1 and indexbyte2 are assembled into an
+ unsigned 16-bit index into the run-time constant pool of the
+ current class ([407]§2.6), where the value of the index is
+ calculated as (indexbyte1 << 8) | indexbyte2. The index must be
+ a valid index into the run-time constant pool of the current
+ class. The run-time constant pool entry at the index must be a
+ run-time constant of type long or double ([408]§5.1). The
+ numeric value of that run-time constant is pushed onto the
+ operand stack as a long or double, respectively.
+
+ Notes
+
+ Only a wide-index version of the ldc2_w instruction exists;
+ there is no ldc2 instruction that pushes a long or double with
+ a single-byte index.
+
+ The ldc2_w instruction can only be used to push a value of type
+ double taken from the double value set ([409]§2.3.2) because a
+ constant of type double in the constant pool ([410]§4.4.5) must
+ be taken from the double value set.
+ "
+
+ "Created: / 29-07-2016 / 09:16:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ldc: index
+ | constantOrRef |
+
+ constantOrRef := constantPool at: index.
+ constantOrRef isJavaRef ifTrue:[
+ constantOrRef isJavaClassRef ifTrue:[
+ refdClasses add: constantOrRef.
+ ].
+ constantOrRef isJavaStringRef ifTrue:[
+ (constantOrRef isResolved or:[ JavaVM booted ]) ifTrue:[
+ constantsAccessed add: constantOrRef resolve.
+ ].
+ ]
+ ] ifFalse:[
+ constantsAccessed add: constantOrRef
+ ].
+
+
+ "
+ Operation
+
+ Push item from run-time constant pool
+
+ Format
+
+ ldc
+ index
+
+ Forms
+
+ ldc = 18 (0x12)
+
+ Operand Stack
+
+ ... →
+
+ ..., value
+
+ Description
+
+ The index is an unsigned byte that must be a valid index into
+ the run-time constant pool of the current class ([384]§2.6).
+ The run-time constant pool entry at index either must be a
+ run-time constant of type int or float, or a reference to a
+ string literal, or a symbolic reference to a class, method
+ type, or method handle ([385]§5.1).
+
+ If the run-time constant pool entry is a run-time constant of
+ type int or float, the numeric value of that run-time constant
+ is pushed onto the operand stack as an int or float,
+ respectively.
+
+ Otherwise, if the run-time constant pool entry is a reference
+ to an instance of class String representing a string literal
+ ([386]§5.1), then a reference to that instance, value, is
+ pushed onto the operand stack.
+
+ Otherwise, if the run-time constant pool entry is a symbolic
+ reference to a class ([387]§5.1), then the named class is
+ resolved ([388]§5.4.3.1) and a reference to the Class object
+ representing that class, value, is pushed onto the operand
+ stack.
+
+ Otherwise, the run-time constant pool entry must be a symbolic
+ reference to a method type or a method handle ([389]§5.1). The
+ method type or method handle is resolved ([390]§5.4.3.5) and a
+ reference to the resulting instance of
+ java.lang.invoke.MethodType or java.lang.invoke.MethodHandle,
+ value, is pushed onto the operand stack.
+
+ Linking Exceptions
+
+ During resolution of a symbolic reference to a class, any of
+ the exceptions pertaining to class resolution ([391]§5.4.3.1)
+ can be thrown.
+
+ During resolution of a symbolic reference to a method type or
+ method handle, any of the exception pertaining to method type
+ or method handle resolution ([392]§5.4.3.5) can be thrown.
+
+ Notes
+
+ The ldc instruction can only be used to push a value of type
+ float taken from the float value set ([393]§2.3.2) because a
+ constant of type float in the constant pool ([394]§4.4.4) must
+ be taken from the float value set.
+ "
+
+ "Created: / 29-07-2016 / 10:17:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
multianewarray
| classRef |
@@ -201,13 +536,15 @@
methodsInvoked := Set new.
refdClasses := Set new.
+ constantsAccessed := Set new.
+
"/ Abstract, native or other funny method
aMethod byteCode isNil ifTrue:[ ^ self ].
^ super process: aMethod receiver: aReceiver arguments: args.
"Created: / 30-08-2013 / 13:23:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 09-09-2013 / 12:15:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-07-2016 / 09:20:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaMethodAnalyzer methodsFor:'queries'!