ObjectFileHandle.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 09:53:22 +0200
changeset 259 a469695d8d19
parent 157 d7f68808a258
child 263 3b21d0991eff
permissions -rw-r--r--
commentary

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 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.
"

Object subclass:#ObjectFileHandle
	instanceVariableNames:'sysHandle1 sysHandle2 pathName moduleID handleType weakMethodRef
		weakClassRefs'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Compiler'
!

!ObjectFileHandle class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 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.
"
!

documentation
"
    not for public use - used by ObjectFileLoader to keep track of loaded modules,
    associating objectFile names and moduleIDs to classes/methods.
"

    "Created: 14.9.1995 / 21:10:55 / claus"
!

history

    "Created: 14.9.1995 / 21:10:55 / claus"
    "Modified: 14.9.1995 / 21:10:55 / claus"
! !

!ObjectFileHandle methodsFor:'accessing'!

classes
    "return the classes"

    weakClassRefs isNil ifTrue:[^nil].
    ^ weakClassRefs asArray 

    "Created: 14.9.1995 / 21:13:13 / claus"
!

classes:aCollectionOfClasses 
    "set the classes collection"

    weakClassRefs := WeakArray withAll:aCollectionOfClasses.
    weakClassRefs addDependent:self.
    handleType := #classLibraryObject 

    "Created: 14.9.1995 / 21:13:13 / claus"
!

method
    "return the method"

    weakMethodRef isNil ifTrue:[^ nil].
    ^ weakMethodRef at:1 

    "Created: 14.9.1995 / 21:13:13 / claus"
!

method:something
    "set the method"

    weakMethodRef := WeakArray with:something.
    weakMethodRef addDependent:self.
    handleType := #methodObject.

    "Created: 14.9.1995 / 21:13:13 / claus"
!

moduleID
    "return moduleID"

    ^ moduleID

    "Created: 14.9.1995 / 21:13:12 / claus"
!

moduleID:something
    "set moduleID"

    moduleID := something.

    "Created: 14.9.1995 / 21:13:12 / claus"
!

pathName
    "return pathName"

    ^ pathName

    "Created: 14.9.1995 / 21:13:12 / claus"
!

pathName:something
    "set pathName"

    pathName := something.

    "Created: 14.9.1995 / 21:13:12 / claus"
!

sysHandle1
    "return sysHandle1"

    ^ sysHandle1

    "Created: 14.9.1995 / 21:13:12 / claus"
!

sysHandle1:something
    "set sysHandle1"

    sysHandle1 := something.

    "Created: 14.9.1995 / 21:13:12 / claus"
!

sysHandle2
    "return sysHandle2"

    ^ sysHandle2

    "Created: 14.9.1995 / 21:13:12 / claus"
!

sysHandle2:something
    "set sysHandle2"

    sysHandle2 := something.

    "Created: 14.9.1995 / 21:13:12 / claus"
! !

!ObjectFileHandle methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    "my method/class object was collected - unload the underlying objectfile"

    self isObsolete ifTrue:[
	('OBJFLOADER: unloading ' , pathName , '  (method/classes were garbageCollected)') infoPrintNL.
	ObjectFileLoader unloadObjectFile:pathName
    ].

    "Created: 5.12.1995 / 18:05:08 / cg"
! !

!ObjectFileHandle methodsFor:'copying'!

postCopy
    "flush module handles of the copy"

    sysHandle1 := sysHandle2 := moduleID := nil

    "Created: 5.12.1995 / 21:10:49 / cg"
    "Modified: 25.4.1996 / 09:43:53 / cg"
! !

!ObjectFileHandle methodsFor:'printing'!

printOn:aStream
    "append a printed representation of the receiver to aStream"

    aStream nextPutAll:self class name; nextPutAll:'(handle=<'. 
    sysHandle1 printOn:aStream. 
    aStream nextPutAll:' '. 
    sysHandle2 printOn:aStream. 
    aStream nextPutAll:'> path='''. 
    pathName printOn:aStream. 
    aStream nextPutAll:''' id='. 
    moduleID printOn:aStream. 
    aStream nextPutAll:' type='. 
    handleType printOn:aStream.
    aStream nextPutAll:' method=<'.
    self method printOn:aStream.
    aStream nextPutAll:'> classes=<'.
    self classes printOn:aStream.
    aStream nextPutAll:'>'.

    aStream nextPutAll:')'.

    "Modified: 25.4.1996 / 09:44:08 / cg"
! !

!ObjectFileHandle methodsFor:'queries'!

isClassLibHandle
    "return true, if I am a handle for a class library"

    ^ handleType == #classLibraryObject 
!

isForCollectedObject
    "return true, if my clases/method has already been garbage collected"

    handleType == #classLibraryObject ifTrue:[
	^ (weakClassRefs findFirst:[:x | x notNil]) == 0
    ].
    handleType == #methodObject ifTrue:[
	^ (weakMethodRef at:1) isNil
    ].
    ^ false

    "Created: 6.12.1995 / 17:46:58 / cg"
!

isMethodHandle
    "return true, if I am a handle for a single compiled method"

    ^ handleType == #methodObject
!

isObsolete
    "return true, if my clases/method has already been removed from
     the image. I.e. if the object file can be unloaded without danger."

    moduleID notNil ifTrue:[
	handleType == #classLibraryObject ifTrue:[
	    ^ (weakClassRefs findFirst:[:x | x notNil]) == 0
	].
	handleType == #methodObject ifTrue:[
	    ^ (weakMethodRef at:1) isNil
	].
    ].
    ^ false
! !

!ObjectFileHandle class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileHandle.st,v 1.13 1996-04-25 07:52:57 cg Exp $'
! !