JavaFieldRef2.st
author Marcel Hlopko <marcel.hlopko@gmail.com>
Sun, 13 Oct 2013 12:04:03 +0200
branchdevelopment
changeset 2825 cace5e1f84f3
parent 2824 6d2d593cb29e
child 2827 b9fadb7c9a1f
permissions -rw-r--r--
experimenting with fieldRef resolving for particular class version

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ Package: 'stx:libjava' }"

JavaClassContentRef2 subclass:#JavaFieldRef2
	instanceVariableNames:'offset type'
	classVariableNames:'T_LONG T_DOUBLE'
	poolDictionaries:''
	category:'Languages-Java-Reader-Support-new'
!

!JavaFieldRef2 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
! !

!JavaFieldRef2 class methodsFor:'initialization'!

initialize
    T_LONG := 1.
    T_DOUBLE := 2.

    "Created: / 15-05-2011 / 22:31:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaFieldRef2 methodsFor:'accessing'!

isJavaFieldRef
^true.

    "Created: / 11-04-2011 / 21:47:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

offset
    ^ offset.

    "Created: / 15-05-2011 / 22:26:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

type
    ^ type.

    "Created: / 15-05-2011 / 22:29:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 05-10-2013 / 23:57:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaFieldRef2 methodsFor:'private - resolving'!

findInstOffset
    "fieldRef must be resolved before calling me"
    self assert: classCache notNil.
    self assert: valueCache notNil.
    ^ classCache instVarOffsetOf: self name.

    "Created: / 07-12-2011 / 13:44:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

findResolvedStaticValue

self findResolvedValue.

    "Created: / 28-04-2011 / 22:05:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 03-12-2011 / 12:16:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-12-2011 / 13:37:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

findResolvedValue: doClassInit
    "
    Stores resolved field in valueCache field, fills offset and 
    type fields.
    "
    valueCache := JavaResolver uniqueInstance 
                resolveFieldIndentifiedByRef: self.
    valueCache isStatic ifTrue: [ classCache := valueCache javaClass ] ifFalse: [
        classCache := self classRef resolve: doClassInit.
    ].
    classCache isNil ifTrue: [ self breakPoint: #mh ].
    self resolveOffset.
    nameAndTypeCache := (constantPool at: nameAndTypeIndex) resolve.
    self resolveType.
    nameAndTypeCache isNil ifTrue: [ self breakPoint: #mh ].

    "Modified: / 07-12-2011 / 21:52:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Created: / 09-02-2012 / 23:09:18 / mh <hlopik@gmail.com>"
    "Modified: / 16-10-2012 / 10:46:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-10-2013 / 17:54:48 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

findStaticOffset
    "fieldRef must be resolved before calling me"
    self assert: classCache notNil.
    self assert: valueCache notNil.
    ^ classCache class instVarOffsetOf: self name.

    "Created: / 07-12-2011 / 13:45:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

preResolve
    self resolveType

    "Created: / 16-10-2012 / 10:45:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

resolveForVersion: javaClass
    "
    Reresolves fieldRef with class cache set to given javaClass. This is the 
    way VM tells us which class version to use. This method is called only when
    there are multiple class versions present.
    "
    self classRef javaClass: javaClass.
    self findResolvedValue: true.

    "Created: / 12-10-2013 / 21:45:54 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

resolveForVersionOf: javaObj or: otherJavaObj
    "
    Reresolves fieldRef with class cache set to given javaClass. This is the 
    way VM tells us which class version to use. This method is called only when
    there are multiple class versions present.
    "
    self classRef javaClass: javaObj javaClass.
    self findResolvedValue: true.

    "Created: / 13-10-2013 / 12:00:04 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

resolveOffset
    "fieldRef must be resolved before calling me"
    
    self assert: valueCache notNil.
    self assert: classCache isJavaClass.
    valueCache isStatic ifTrue: [ offset := self findStaticOffset. ] ifFalse: [
        offset := self findInstOffset.
    ].
    self assert: offset notNil.

    "Modified: / 07-12-2011 / 21:47:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

resolveStaticOffset
    "fieldRef must be resolved before calling me"
    
    | currentClass |
    currentClass := classCache.
    self assert: (currentClass class instVarNames includes: self name).
    offset := currentClass class instVarOffsetOf: self name.

    "Modified: / 07-12-2011 / 13:38:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

resolveType
    | descriptor |

    descriptor := (constantPool at: nameAndTypeIndex) descriptor.
    type := 0.
    descriptor = 'J' ifTrue:[
        type := T_LONG.
    ] ifFalse:[
        descriptor = 'D' ifTrue:[
            type := T_DOUBLE
        ]
    ].

    "Created: / 15-05-2011 / 22:29:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 05-10-2013 / 23:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaFieldRef2 class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libjava/JavaFieldRef2.st,v 1.6 2013-09-06 00:41:23 vrany Exp $'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ 'Id'
! !


JavaFieldRef2 initialize!