ProtoObject.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 17 Jun 2015 06:22:00 +0100
branchjv
changeset 18487 8735bd9eee2f
parent 18442 bd42fa983e3f
child 19691 5e613f6255d9
permissions -rw-r--r--
Use inlined FNV1a hash for String ...and do not use __symbolHash(). Although currently the VM also uses FNV1a hash for Symbols, the __symbolHash() does not handle properly character with codepoint 0 (because '\0' is used as a string terminator). This causes problems with Unicode16/32Strigs whose version of FNV1a hash is using object size from header to determine string's end. Added Symbol>>hash that actually *uses* the __symbolHash() to make sure it's hash is the the same as used bu the VM. Symbols with zeroes are rare and there's no Unicode16/32Symbol. This commit fixes issue #65.

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 2004 by eXept Software AG
              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.
"
"{ Package: 'stx:libbasic' }"

"{ NameSpace: Smalltalk }"

nil subclass:#ProtoObject
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Objects'
!

!ProtoObject class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2004 by eXept Software AG
              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
"
    a minimum object without much protocol;
    Provides the minimum required to prevent inspectors from crashing,
    and debuggers from blocking.
    (i.e. instead of inheriting from nil, better inherit from this).

    Named after a similar class found in Dolphin-Smalltalk.

    [author:]
        Claus Gittinger (not much authoring, though)
"
! !

!ProtoObject methodsFor:'error handling'!

doesNotUnderstand:aMessage
    "this message is sent by the runtime system (VM) when
     a message is not understood by some object (i.e. there
     is no method for that selector). The original message has
     been packed into aMessage (i.e. the receiver, selector and
     any arguments) and the original receiver is then sent the
     #doesNotUnderstand: message.
     Here, we raise another signal which usually enters the debugger.
     You can of course redefine #doesNotUnderstand: in your classes
     to implement message delegation, 
     or handle the MessageNotUnderstood exception gracefully."

    <context: #return>

    ^ MessageNotUnderstood raiseRequestWith:aMessage
! !

!ProtoObject methodsFor:'queries'!

class
    "return the receivers class"

%{  /* NOCONTEXT */

    RETURN ( __Class(self) );
%}

"
*** WARNING
***
*** this method has been automatically created,
*** since all nil-subclasses should respond to some minimum required
*** protocol.
***
*** Inspection and/or debugging of instances may not be possible,
*** if you remove/change this method. 
"
!

identityHash
    "return an Integer useful as a hash key for the receiver.
     This hash should return same values for the same object (i.e. use
     this to hash on identity of objects).

     We cannot use the Objects address (as other smalltalks do) since
     no object-table exists and the hashval must not change when objects
     are moved by the collector. Therefore we assign each object a unique
     Id in the object header itself as its hashed upon.
     (luckily we have 11 bits spare to do this - unluckily its only 11 bits).
     Time will show, if 11 bits are enough; if not, another entry in the
     object header will be needed, adding 4 bytes to every object. Alternatively,
     hashed-upon objects could add an instvar containing the hash value."

%{  /* NOCONTEXT */

    REGISTER unsigned INT hash;
    static unsigned nextHash = 0;

    if (__isNonNilObject(self)) {
        hash = __GET_HASH(self);
        if (hash == 0) {
            /* has no hash yet */

            if (++nextHash > __MAX_HASH__) {
                nextHash = 1;
            }
            hash = nextHash;
            __SET_HASH(self, hash);
        }

        /*
         * now, we got 11 bits for hashing;
         * make it as large as possible; since most hashers use the returned
         * key and take it modulo some prime number, this will allow for
         * better distribution (i.e. bigger empty spaces) in hashed collection.
         */
        hash = __MAKE_HASH__(hash);
        RETURN ( __mkSmallInteger(hash) );
    }
%}.
    ^ 0 "never reached, since redefined in UndefinedObject and SmallInteger"

    "Created: / 31-05-2007 / 23:18:40 / cg"
! !

!ProtoObject methodsFor:'testing'!

ifNil:aBlock
    ^ self
!

ifNotNil:aBlockOrValue
    (aBlockOrValue isBlock and:[aBlockOrValue argumentCount == 1]) ifTrue:[
        ^ aBlockOrValue value:self.
    ].
    ^ aBlockOrValue value
!

isBehavior
    "return true, if the receiver is describing another object's behavior.
     False is returned here - the method is only redefined in Behavior."

    ^ false
!

isBlock
    ^ false
!

isException
    ^ false
!

isExceptionHandler
    ^ false
!

isJavaObject
    ^ false
!

isLazyValue
    ^ false

    "Created: / 03-06-2007 / 14:02:12 / cg"
!

isLiteral
    ^ false

    "Created: / 04-06-2007 / 17:19:10 / cg"
! !

!ProtoObject class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/ProtoObject.st,v 1.16 2015-06-05 16:10:58 stefan Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic/ProtoObject.st,v 1.16 2015-06-05 16:10:58 stefan Exp $'
! !