JavaExceptionTable.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 24 May 2013 17:55:42 +0100
branchbuiltin-class-support
changeset 2629 cedb88626902
parent 2585 14ab287e17ca
child 2711 a00302fe5083
permissions -rw-r--r--
Closing branch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2585
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
 This software is furnished under a license and may be used
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
 hereby transferred.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
     see the differences between this version and version stx:libjava
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
     as of 1.9.2010
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
WordArray variableWordSubclass:#JavaExceptionTable
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
	instanceVariableNames:''
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
	classVariableNames:''
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
	poolDictionaries:''
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
	category:'Languages-Java-Support'
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
!
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
!JavaExceptionTable class methodsFor:'documentation'!
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
copyright
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
 New code and modifications done at SWING Research Group [1]:
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
                            SWING Research Group, Czech Technical University in Prague
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
 This software is furnished under a license and may be used
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
 only in accordance with the terms of that license and with the
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
 be provided or otherwise made available to, or used by, any
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
 other person.  No title to or ownership of the software is
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
 hereby transferred.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
 [1] Code written at SWING Research Group contains a signature
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
     of one of the above copright owners. For exact set of such code,
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
     see the differences between this version and version stx:libjava
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
     as of 1.9.2010
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
! !
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
!JavaExceptionTable methodsFor:'accessing'!
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
handlerPCFor:exception at:pc in:aMethod
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
    "if there is a handler for exceptionClass, with given pc,
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
     return the handler-PC; otherwise, return nil."
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
    | i |
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
    "JV+MH@2011-02-25: You may wonder why there is endPC - 1:
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
    The Java VM Spec, 3rd edition, sec 4.7.3, page 78:
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
    The fact that end_pc is exclusive is a historical mistake in the design of the
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
    Java virtual machine: if the Java virtual machine code for a method is exactly
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
    65535 bytes long and ends with an instruction that is 1 byte long, then that
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
    instruction cannot be protected by an exception handler. A compiler writer can
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
    work around this bug by limiting the maximum size of the generated Java
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
    virtual machine code for any method, instance initialization method, or static
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
    initializer (the size of any code array) to 65534 bytes.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
    "
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
    i := 1.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
    [ i < self size ] whileTrue:[
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
        | startPC endPC handlerPC catchType |
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
        startPC := self at: i.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
        endPC := self at: i + 1.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
        handlerPC := self at: i + 2.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
        catchType := self at: i + 3.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
        (pc between:startPC and:endPC - 1) ifTrue:[
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
            (catchType == 0) ifTrue:[^ handlerPC].
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
            exception notNil ifTrue:[
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
                catchType := (aMethod constantPool at: catchType) javaClass.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
                (exception isKindOf:catchType) ifTrue:[
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
                    ^ handlerPC
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
                ].
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
            ]
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
        ].
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
        i := i + 4.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
    ].
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
    ^ nil
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
    "Created: / 06-05-2013 / 21:55:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
! !
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
!JavaExceptionTable methodsFor:'queries'!
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   101
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   102
hasFinallyBasedOnExceptionTable
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   103
    | i |
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   104
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   105
    i := 1.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
    [ i < self size ] whileTrue:[
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
        (self at: i + 3) == 0 ifTrue:[ ^ true ].
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
        i := i + 4.
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
    ].
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
    ^ false
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
    "Created: / 06-05-2013 / 21:59:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
! !
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
!JavaExceptionTable class methodsFor:'documentation'!
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
version_HG
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
    ^ '$Changeset: <not expanded> $'
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
! !
14ab287e17ca Exception table refactored to use more compact & VM friendly format.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121