src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/SignatureIterator.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 35217 hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/SignatureIterator.java@ce4b5303a813
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.runtime;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
/** <P> SignatureIterators iterate over a Java signature (or parts of it).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
    (Syntax according to: "The Java Virtual Machine Specification" by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
    Tim Lindholm & Frank Yellin; section 4.3 Descriptors; p. 89ff.) </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    <P> Example: Iterating over
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
<PRE>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
([Lfoo;D)I
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
0123456789
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
</PRE>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    using </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
<PRE>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
iterateParameters() calls: do_array(2, 7); do_double();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
iterateReturntype() calls:                              do_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
iterate()           calls: do_array(2, 7); do_double(); do_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
is_returnType()        is: false         ; false      ; true
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
</PRE>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
public abstract class SignatureIterator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  protected Symbol _signature;       // the signature to iterate over
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  protected int    _index;           // the current character index (only valid during iteration)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  protected int    _parameter_index; // the current parameter index (0 outside iteration phase)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  protected void expect(char c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    if (_signature.getByteAt(_index) != (byte) c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
      throw new RuntimeException("expecting '" + c + "'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  protected void skipOptionalSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    byte c = _signature.getByteAt(_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    while ('0' <= c && c <= '9') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      c = _signature.getByteAt(++_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // returns the parameter size in words (0 for void)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  protected int parseType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    switch(_signature.getByteAt(_index)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    case 'B': doByte  (); _index++; return BasicTypeSize.getTByteSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    case 'C': doChar  (); _index++; return BasicTypeSize.getTCharSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    case 'D': doDouble(); _index++; return BasicTypeSize.getTDoubleSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    case 'F': doFloat (); _index++; return BasicTypeSize.getTFloatSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    case 'I': doInt   (); _index++; return BasicTypeSize.getTIntSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    case 'J': doLong  (); _index++; return BasicTypeSize.getTLongSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    case 'S': doShort (); _index++; return BasicTypeSize.getTShortSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    case 'Z': doBool  (); _index++; return BasicTypeSize.getTBooleanSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    case 'V':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
        if (!isReturnType()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
          throw new RuntimeException("illegal parameter type V (void)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        doVoid(); _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        return BasicTypeSize.getTVoidSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    case 'L':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
        int begin = ++_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        while (_signature.getByteAt(_index++) != ';') ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        doObject(begin, _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        return BasicTypeSize.getTObjectSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    case '[':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
        int begin = ++_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        skipOptionalSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        while (_signature.getByteAt(_index) == '[') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
          _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
          skipOptionalSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
        if (_signature.getByteAt(_index) == 'L') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
          while (_signature.getByteAt(_index++) != ';') ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
          _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        doArray(begin, _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        return BasicTypeSize.getTArraySize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 1
diff changeset
   111
    throw new RuntimeException("Should not reach here: char " + (char)_signature.getByteAt(_index) + " @ " + _index + " in " + _signature.asString());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  protected void checkSignatureEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    if (_index < _signature.getLength()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      System.err.println("too many chars in signature");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      _signature.printValueOn(System.err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      System.err.println(" @ " + _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public SignatureIterator(Symbol signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    _signature       = signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // dispatches once for field signatures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  public void dispatchField() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // no '(', just one (field) type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    parseType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    checkSignatureEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // iterates over parameters only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public void iterateParameters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    // Parse parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    expect('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    while (_signature.getByteAt(_index) != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      _parameter_index += parseType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    expect(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    _parameter_index = 0; // so isReturnType() is false outside iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // iterates over returntype only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  public void iterateReturntype() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    // Ignore parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    expect('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    while (_signature.getByteAt(_index) != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    expect(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    // Parse return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    _parameter_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    parseType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    checkSignatureEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    _parameter_index = 0; // so isReturnType() is false outside iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // iterates over whole signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  public void iterate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    // Parse parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    expect('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    while (_signature.getByteAt(_index) != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      _parameter_index += parseType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    expect(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    // Parse return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    _parameter_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    parseType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    checkSignatureEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    _parameter_index = 0; // so isReturnType() is false outside iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Returns the word index of the current parameter; returns a negative value at the return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  public int  parameterIndex()               { return _parameter_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  public boolean isReturnType()              { return (parameterIndex() < 0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // Basic types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  public abstract void doBool  ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  public abstract void doChar  ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  public abstract void doFloat ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  public abstract void doDouble();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  public abstract void doByte  ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  public abstract void doShort ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  public abstract void doInt   ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  public abstract void doLong  ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  public abstract void doVoid  ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // Object types (begin indexes the first character of the entry, end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // indexes the first character after the entry)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  public abstract void doObject(int begin, int end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  public abstract void doArray (int begin, int end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}