hotspot/src/share/vm/runtime/signature.cpp
author phh
Wed, 28 Oct 2009 16:25:51 -0400
changeset 4434 4b41e5b42f81
parent 1 489c9b5090e2
child 5421 e294db54fc0d
child 5403 6b0dd9c75dde
permissions -rw-r--r--
6887571: Increase default heap config sizes Summary: Apply modification of existing server heap size ergo to all collectors except CMS. Reviewed-by: jmasa, ysr, xlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_signature.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Implementation of SignatureIterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Signature syntax:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Signature  = "(" {Parameter} ")" ReturnType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Parameter  = FieldType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// ReturnType = FieldType | "V".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// FieldType  = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// ClassName  = string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
SignatureIterator::SignatureIterator(symbolHandle signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  assert(signature->is_symbol(), "not a symbol");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _signature       = signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Overloaded version called without handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
SignatureIterator::SignatureIterator(symbolOop signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  symbolHandle sh(Thread::current(), signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _signature       = sh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
SignatureIterator::SignatureIterator(Thread *thread, symbolOop signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  symbolHandle sh(thread, signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _signature       = sh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
void SignatureIterator::expect(char c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (_signature->byte_at(_index) != c) fatal1("expecting %c", c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
void SignatureIterator::skip_optional_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  symbolOop sig = _signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  char c = sig->byte_at(_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  while ('0' <= c && c <= '9') c = sig->byte_at(++_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
int SignatureIterator::parse_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Note: This function could be simplified by using "return T_XXX_size;"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  //       instead of the assignment and the break statements. However, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  //       seems that the product build for win32_i486 with MS VC++ 6.0 doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  //       work (stack underflow for some tests) - this seems to be a VC++ 6.0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  //       compiler bug (was problem - gri 4/27/2000).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  int size = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  switch(_signature->byte_at(_index)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    case 'B': do_byte  (); if (_parameter_index < 0 ) _return_type = T_BYTE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
              _index++; size = T_BYTE_size   ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    case 'C': do_char  (); if (_parameter_index < 0 ) _return_type = T_CHAR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
              _index++; size = T_CHAR_size   ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
              _index++; size = T_DOUBLE_size ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
              _index++; size = T_FLOAT_size  ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    case 'I': do_int   (); if (_parameter_index < 0 ) _return_type = T_INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
              _index++; size = T_INT_size    ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    case 'J': do_long  (); if (_parameter_index < 0 ) _return_type = T_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
              _index++; size = T_LONG_size   ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
              _index++; size = T_SHORT_size  ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    case 'Z': do_bool  (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
              _index++; size = T_BOOLEAN_size; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    case 'V': do_void  (); if (_parameter_index < 0 ) _return_type = T_VOID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
              _index++; size = T_VOID_size;  ; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    case 'L':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      { int begin = ++_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        symbolOop sig = _signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        while (sig->byte_at(_index++) != ';') ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
        do_object(begin, _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      if (_parameter_index < 0 ) _return_type = T_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      size = T_OBJECT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    case '[':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      { int begin = ++_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        skip_optional_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        symbolOop sig = _signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        while (sig->byte_at(_index) == '[') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
          _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
          skip_optional_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        if (sig->byte_at(_index) == 'L') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
          while (sig->byte_at(_index++) != ';') ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
          _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        do_array(begin, _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
       if (_parameter_index < 0 ) _return_type = T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      size = T_ARRAY_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  assert(size >= 0, "size must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
void SignatureIterator::check_signature_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  if (_index < _signature->utf8_length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    tty->print_cr("too many chars in signature");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    _signature->print_value_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    tty->print_cr(" @ %d", _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
void SignatureIterator::dispatch_field() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // no '(', just one (field) type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  check_signature_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
void SignatureIterator::iterate_parameters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Parse parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  expect('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  expect(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
// Optimized version of iterat_parameters when fingerprint is known
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  uint64_t saved_fingerprint = fingerprint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // Check for too many arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if ( fingerprint == UCONST64(-1) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    SignatureIterator::iterate_parameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(fingerprint, "Fingerprint should not be 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  fingerprint = fingerprint >> (static_feature_size + result_feature_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  while ( 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    switch ( fingerprint & parameter_feature_mask ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      case bool_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        do_bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        _parameter_index += T_BOOLEAN_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      case byte_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        do_byte();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        _parameter_index += T_BYTE_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      case char_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        do_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        _parameter_index += T_CHAR_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      case short_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        do_short();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        _parameter_index += T_SHORT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      case int_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        do_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        _parameter_index += T_INT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      case obj_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        do_object(0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
        _parameter_index += T_OBJECT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      case long_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
        do_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        _parameter_index += T_LONG_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      case float_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        do_float();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        _parameter_index += T_FLOAT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      case double_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        do_double();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        _parameter_index += T_DOUBLE_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      case done_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        tty->print_cr("*** parameter is %d", fingerprint & parameter_feature_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    fingerprint >>= parameter_feature_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
void SignatureIterator::iterate_returntype() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Ignore parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  expect('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  symbolOop sig = _signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  while (sig->byte_at(_index) != ')') _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  expect(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // Parse return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  _parameter_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  check_signature_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
void SignatureIterator::iterate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // Parse parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  expect('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  expect(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // Parse return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  _parameter_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  check_signature_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
// Implementation of SignatureStream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
bool SignatureStream::is_done() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  return _end > _signature()->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
void SignatureStream::next_non_primitive(int t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    case 'L': {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      _type = T_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      symbolOop sig = _signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      while (sig->byte_at(_end++) != ';');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    case '[': {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      _type = T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      symbolOop sig = _signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      char c = sig->byte_at(_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      while (sig->byte_at(_end) == '[') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        _end++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        c = sig->byte_at(_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
      switch(sig->byte_at(_end)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        case 'B':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
        case 'C':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        case 'D':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
        case 'F':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
        case 'I':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
        case 'J':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
        case 'S':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
        case 'Z':_end++; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
        default: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
          while (sig->byte_at(_end++) != ';');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    case ')': _end++; next(); _at_return_type = true; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    default : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
bool SignatureStream::is_object() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  return _type == T_OBJECT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      || _type == T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
bool SignatureStream::is_array() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  return _type == T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
symbolOop SignatureStream::as_symbol(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // Create a symbol from for string _begin _end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  int begin = _begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  int end   = _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  if (   _signature()->byte_at(_begin) == 'L'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      && _signature()->byte_at(_end-1) == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    begin++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    end--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  symbolOop result = oopFactory::new_symbol(_signature, begin, end, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
symbolOop SignatureStream::as_symbol_or_null() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // Create a symbol from for string _begin _end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  int begin = _begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  int end   = _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  if (   _signature()->byte_at(_begin) == 'L'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      && _signature()->byte_at(_end-1) == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    begin++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    end--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  for (int index = begin; index < end; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    buffer[index - begin] = _signature()->byte_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  symbolOop result = SymbolTable::probe(buffer, end - begin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
bool SignatureVerifier::is_valid_signature(symbolHandle sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  const char* signature = (const char*)sig->bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  ssize_t len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  if (signature == NULL || signature[0] == '\0' || len < 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  } else if (signature[0] == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    return is_valid_method_signature(sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    return is_valid_type_signature(sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
bool SignatureVerifier::is_valid_method_signature(symbolHandle sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  const char* method_sig = (const char*)sig->bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  ssize_t len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  ssize_t index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    while (index < len && method_sig[index] != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      ssize_t res = is_valid_type(&method_sig[index], len - index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      if (res == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
        index += res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    if (index < len && method_sig[index] == ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      // check the return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      return (is_valid_type(&method_sig[index], len - index) == (len - index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
bool SignatureVerifier::is_valid_type_signature(symbolHandle sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  const char* type_sig = (const char*)sig->bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  ssize_t len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  return (type_sig != NULL && len >= 1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
          (is_valid_type(type_sig, len) == len));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
// Checks to see if the type (not to go beyond 'limit') refers to a valid type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
// Returns -1 if it is not, or the index of the next character that is not part
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
// of the type.  The type encoding may end before 'limit' and that's ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  ssize_t index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // Iterate over any number of array dimensions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  while (index < limit && type[index] == '[') ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  if (index >= limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  switch (type[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    case 'B': case 'C': case 'D': case 'F': case 'I':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    case 'J': case 'S': case 'Z': case 'V':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      return index + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    case 'L':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      for (index = index + 1; index < limit; ++index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
        char c = type[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
        if (c == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
          return index + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
        if (invalid_name_char(c)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
          return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    default: ; // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
bool SignatureVerifier::invalid_name_char(char c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  switch (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    case '\0': case '.': case ';': case '[':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
}