src/hotspot/share/runtime/signature.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 54847 59ea39bb2809
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54124
5d48ae032588 8219579: Remove redundant signature parsing from the verifier
hseigel
parents: 51997
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 5426
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5426
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: 5426
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/oopFactory.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33148
diff changeset
    29
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54133
diff changeset
    30
#include "memory/universe.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "oops/oop.inline.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    33
#include "oops/symbol.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "oops/typeArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/signature.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Implementation of SignatureIterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Signature syntax:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Signature  = "(" {Parameter} ")" ReturnType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Parameter  = FieldType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// ReturnType = FieldType | "V".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// FieldType  = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// ClassName  = string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    48
SignatureIterator::SignatureIterator(Symbol* signature) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _signature       = signature;
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
void SignatureIterator::expect(char c) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
    54
  if (_signature->char_at(_index) != c) fatal("expecting %c", c);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
int SignatureIterator::parse_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Note: This function could be simplified by using "return T_XXX_size;"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  //       instead of the assignment and the break statements. However, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  //       seems that the product build for win32_i486 with MS VC++ 6.0 doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  //       work (stack underflow for some tests) - this seems to be a VC++ 6.0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  //       compiler bug (was problem - gri 4/27/2000).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  int size = -1;
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
    65
  switch(_signature->char_at(_index)) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    66
    case JVM_SIGNATURE_BYTE:    do_byte(); if (_parameter_index < 0 ) _return_type = T_BYTE;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    67
                                  _index++; size = T_BYTE_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    68
    case JVM_SIGNATURE_CHAR:    do_char(); if (_parameter_index < 0 ) _return_type = T_CHAR;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    69
                                  _index++; size = T_CHAR_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    70
    case JVM_SIGNATURE_DOUBLE:  do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    71
                                  _index++; size = T_DOUBLE_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    72
    case JVM_SIGNATURE_FLOAT:   do_float(); if (_parameter_index < 0 ) _return_type = T_FLOAT;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    73
                                  _index++; size = T_FLOAT_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    74
    case JVM_SIGNATURE_INT:     do_int(); if (_parameter_index < 0 ) _return_type = T_INT;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    75
                                  _index++; size = T_INT_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    76
    case JVM_SIGNATURE_LONG:    do_long(); if (_parameter_index < 0 ) _return_type = T_LONG;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    77
                                  _index++; size = T_LONG_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    78
    case JVM_SIGNATURE_SHORT:   do_short(); if (_parameter_index < 0 ) _return_type = T_SHORT;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    79
                                  _index++; size = T_SHORT_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    80
    case JVM_SIGNATURE_BOOLEAN: do_bool(); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    81
                                  _index++; size = T_BOOLEAN_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    82
    case JVM_SIGNATURE_VOID:    do_void(); if (_parameter_index < 0 ) _return_type = T_VOID;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    83
                                  _index++; size = T_VOID_size; break;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    84
    case JVM_SIGNATURE_CLASS:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      { int begin = ++_index;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    86
        Symbol* sig = _signature;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    87
        while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        do_object(begin, _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      if (_parameter_index < 0 ) _return_type = T_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      size = T_OBJECT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      break;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    93
    case JVM_SIGNATURE_ARRAY:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      { int begin = ++_index;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    95
        Symbol* sig = _signature;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    96
        while (sig->char_at(_index) == JVM_SIGNATURE_ARRAY) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
          _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
    99
        if (sig->char_at(_index) == JVM_SIGNATURE_CLASS) {
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   100
          while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
          _index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        do_array(begin, _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
       if (_parameter_index < 0 ) _return_type = T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      size = T_ARRAY_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(size >= 0, "size must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
void SignatureIterator::check_signature_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  if (_index < _signature->utf8_length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    tty->print_cr("too many chars in signature");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    _signature->print_value_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    tty->print_cr(" @ %d", _index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
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
void SignatureIterator::iterate_parameters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Parse parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  _parameter_index = 0;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   131
  expect(JVM_SIGNATURE_FUNC);
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   132
  while (_signature->char_at(_index) != JVM_SIGNATURE_ENDFUNC) _parameter_index += parse_type();
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   133
  expect(JVM_SIGNATURE_ENDFUNC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   137
// Optimized version of iterate_parameters when fingerprint is known
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  uint64_t saved_fingerprint = fingerprint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Check for too many arguments
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 24424
diff changeset
   142
  if (fingerprint == (uint64_t)CONST64(-1)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    SignatureIterator::iterate_parameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  assert(fingerprint, "Fingerprint should not be 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  fingerprint = fingerprint >> (static_feature_size + result_feature_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  while ( 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    switch ( fingerprint & parameter_feature_mask ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      case bool_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        do_bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        _parameter_index += T_BOOLEAN_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      case byte_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        do_byte();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        _parameter_index += T_BYTE_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      case char_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        do_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        _parameter_index += T_CHAR_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      case short_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        do_short();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        _parameter_index += T_SHORT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      case int_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        do_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        _parameter_index += T_INT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      case obj_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        do_object(0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        _parameter_index += T_OBJECT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      case long_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        do_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        _parameter_index += T_LONG_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      case float_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        do_float();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        _parameter_index += T_FLOAT_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      case double_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        do_double();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        _parameter_index += T_DOUBLE_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      case done_parm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      default:
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   192
        tty->print_cr("*** parameter is " UINT64_FORMAT, fingerprint & parameter_feature_mask);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    fingerprint >>= parameter_feature_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
void SignatureIterator::iterate_returntype() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // Ignore parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  _index = 0;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   205
  expect(JVM_SIGNATURE_FUNC);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   206
  Symbol* sig = _signature;
41545
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   207
  // Need to skip over each type in the signature's argument list until a
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   208
  // closing ')' is found., then get the return type.  We cannot just scan
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   209
  // for the first ')' because ')' is a legal character in a type name.
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   210
  while (sig->char_at(_index) != JVM_SIGNATURE_ENDFUNC) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   211
    switch(sig->char_at(_index)) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   212
      case JVM_SIGNATURE_BYTE:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   213
      case JVM_SIGNATURE_CHAR:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   214
      case JVM_SIGNATURE_DOUBLE:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   215
      case JVM_SIGNATURE_FLOAT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   216
      case JVM_SIGNATURE_INT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   217
      case JVM_SIGNATURE_LONG:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   218
      case JVM_SIGNATURE_SHORT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   219
      case JVM_SIGNATURE_BOOLEAN:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   220
      case JVM_SIGNATURE_VOID:
41545
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   221
        {
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   222
          _index++;
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   223
        }
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   224
        break;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   225
      case JVM_SIGNATURE_CLASS:
41545
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   226
        {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   227
          while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
41545
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   228
        }
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   229
        break;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   230
      case JVM_SIGNATURE_ARRAY:
41545
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   231
        {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   232
          while (sig->char_at(++_index) == JVM_SIGNATURE_ARRAY) ;
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   233
          if (sig->char_at(_index) == JVM_SIGNATURE_CLASS) {
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   234
            while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
41545
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   235
          } else {
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   236
            _index++;
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   237
          }
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   238
        }
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   239
        break;
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   240
      default:
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   241
        ShouldNotReachHere();
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   242
        break;
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   243
    }
45a3f587a838 8157176: Improved classfile parsing
hseigel
parents: 37248
diff changeset
   244
  }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   245
  expect(JVM_SIGNATURE_ENDFUNC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // Parse return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  _parameter_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  check_signature_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
void SignatureIterator::iterate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // Parse parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  _index = 0;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   258
  expect(JVM_SIGNATURE_FUNC);
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   259
  while (_signature->char_at(_index) != JVM_SIGNATURE_ENDFUNC) _parameter_index += parse_type();
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   260
  expect(JVM_SIGNATURE_ENDFUNC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // Parse return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  _parameter_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  parse_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  check_signature_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  _parameter_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
// Implementation of SignatureStream
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   270
SignatureStream::SignatureStream(Symbol* signature, bool is_method) :
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   271
                   _signature(signature), _at_return_type(false), _previous_name(NULL), _names(NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   272
  _begin = _end = (is_method ? 1 : 0);  // skip first '(' in method signatures
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   273
  next();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   274
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   275
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   276
SignatureStream::~SignatureStream() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   277
  // decrement refcount for names created during signature parsing
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   278
  if (_names != NULL) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   279
    for (int i = 0; i < _names->length(); i++) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   280
      _names->at(i)->decrement_refcount();
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   281
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   282
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   283
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
bool SignatureStream::is_done() const {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   286
  return _end > _signature->utf8_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
void SignatureStream::next_non_primitive(int t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  switch (t) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   292
    case JVM_SIGNATURE_CLASS: {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      _type = T_OBJECT;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   294
      Symbol* sig = _signature;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   295
      while (sig->char_at(_end++) != JVM_SIGNATURE_ENDCLASS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   298
    case JVM_SIGNATURE_ARRAY: {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      _type = T_ARRAY;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   300
      Symbol* sig = _signature;
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   301
      char c = sig->char_at(_end);
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   302
      while ('0' <= c && c <= '9') c = sig->char_at(_end++);
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   303
      while (sig->char_at(_end) == JVM_SIGNATURE_ARRAY) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
        _end++;
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   305
        c = sig->char_at(_end);
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   306
        while ('0' <= c && c <= '9') c = sig->char_at(_end++);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      }
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   308
      switch(sig->char_at(_end)) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   309
        case JVM_SIGNATURE_BYTE:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   310
        case JVM_SIGNATURE_CHAR:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   311
        case JVM_SIGNATURE_DOUBLE:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   312
        case JVM_SIGNATURE_FLOAT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   313
        case JVM_SIGNATURE_INT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   314
        case JVM_SIGNATURE_LONG:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   315
        case JVM_SIGNATURE_SHORT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   316
        case JVM_SIGNATURE_BOOLEAN:_end++; break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
        default: {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   318
          while (sig->char_at(_end++) != JVM_SIGNATURE_ENDCLASS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   324
    case JVM_SIGNATURE_ENDFUNC: _end++; next(); _at_return_type = true; break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    default : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
bool SignatureStream::is_object() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  return _type == T_OBJECT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      || _type == T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
bool SignatureStream::is_array() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  return _type == T_ARRAY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   339
Symbol* SignatureStream::as_symbol() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // Create a symbol from for string _begin _end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  int begin = _begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  int end   = _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   344
  if (   _signature->char_at(_begin) == JVM_SIGNATURE_CLASS
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   345
      && _signature->char_at(_end-1) == JVM_SIGNATURE_ENDCLASS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    begin++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    end--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   350
  const char* symbol_chars = (const char*)_signature->base() + begin;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   351
  int len = end - begin;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   352
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   353
  // Quick check for common symbols in signatures
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   354
  assert((vmSymbols::java_lang_String()->utf8_length() == 16 && vmSymbols::java_lang_Object()->utf8_length() == 16), "sanity");
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   355
  if (len == 16 &&
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   356
      strncmp(symbol_chars, "java/lang/", 10) == 0) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   357
    if (strncmp("String", symbol_chars + 10, 6) == 0) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   358
      return vmSymbols::java_lang_String();
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   359
    } else if (strncmp("Object", symbol_chars + 10, 6) == 0) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   360
      return vmSymbols::java_lang_Object();
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   361
    }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   362
  }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   363
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   364
  Symbol* name = _previous_name;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   365
  if (name != NULL && name->equals(symbol_chars, len)) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   366
    return name;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   367
  }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   368
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   369
  // Save names for cleaning up reference count at the end of
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   370
  // SignatureStream scope.
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   371
  name = SymbolTable::new_symbol(symbol_chars, len);
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   372
  if (!name->is_permanent()) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   373
    if (_names == NULL) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   374
      _names = new GrowableArray<Symbol*>(10);
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   375
    }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   376
    _names->push(name);  // save new symbol for decrementing later
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   377
  }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   378
  _previous_name = name;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   379
  return name;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8921
diff changeset
   382
Klass* SignatureStream::as_klass(Handle class_loader, Handle protection_domain,
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   383
                                 FailureMode failure_mode, TRAPS) {
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   384
  if (!is_object())  return NULL;
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   385
  Symbol* name = as_symbol();
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   386
  if (failure_mode == ReturnNull) {
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   387
    return SystemDictionary::resolve_or_null(name, class_loader, protection_domain, THREAD);
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   388
  } else {
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   389
    bool throw_error = (failure_mode == NCDFError);
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   390
    return SystemDictionary::resolve_or_fail(name, class_loader, protection_domain, throw_error, THREAD);
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   391
  }
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   392
}
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   393
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   394
oop SignatureStream::as_java_mirror(Handle class_loader, Handle protection_domain,
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   395
                                    FailureMode failure_mode, TRAPS) {
48836
423bcbb288ff 8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents: 48826
diff changeset
   396
  if (!is_object())
423bcbb288ff 8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents: 48826
diff changeset
   397
    return Universe::java_mirror(type());
423bcbb288ff 8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents: 48826
diff changeset
   398
  Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL);
423bcbb288ff 8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents: 48826
diff changeset
   399
  if (klass == NULL)  return NULL;
423bcbb288ff 8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents: 48826
diff changeset
   400
  return klass->java_mirror();
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 1
diff changeset
   401
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   403
Symbol* SignatureStream::as_symbol_or_null() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // Create a symbol from for string _begin _end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  int begin = _begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  int end   = _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   410
  if (   _signature->char_at(_begin) == JVM_SIGNATURE_CLASS
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   411
      && _signature->char_at(_end-1) == JVM_SIGNATURE_ENDCLASS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    begin++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    end--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  for (int index = begin; index < end; index++) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
   418
    buffer[index - begin] = _signature->char_at(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   420
  Symbol* result = SymbolTable::probe(buffer, end - begin);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   424
int SignatureStream::reference_parameter_count() {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   425
  int args_count = 0;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   426
  for ( ; !at_return_type(); next()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   427
    if (is_object()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   428
      args_count++;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   429
    }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   430
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   431
  return args_count;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   432
}
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 14488
diff changeset
   433
54124
5d48ae032588 8219579: Remove redundant signature parsing from the verifier
hseigel
parents: 51997
diff changeset
   434
#ifdef ASSERT
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   435
bool SignatureVerifier::is_valid_method_signature(Symbol* sig) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  const char* method_sig = (const char*)sig->bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  ssize_t len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  ssize_t index = 0;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   439
  if (method_sig != NULL && len > 1 && method_sig[index] == JVM_SIGNATURE_FUNC) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    ++index;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   441
    while (index < len && method_sig[index] != JVM_SIGNATURE_ENDFUNC) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      ssize_t res = is_valid_type(&method_sig[index], len - index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      if (res == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        index += res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   449
    if (index < len && method_sig[index] == JVM_SIGNATURE_ENDFUNC) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
      // check the return type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      return (is_valid_type(&method_sig[index], len - index) == (len - index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   458
bool SignatureVerifier::is_valid_type_signature(Symbol* sig) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  const char* type_sig = (const char*)sig->bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  ssize_t len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  return (type_sig != NULL && len >= 1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
          (is_valid_type(type_sig, len) == len));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
// Checks to see if the type (not to go beyond 'limit') refers to a valid type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
// Returns -1 if it is not, or the index of the next character that is not part
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
// of the type.  The type encoding may end before 'limit' and that's ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  ssize_t index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  // Iterate over any number of array dimensions
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   472
  while (index < limit && type[index] == JVM_SIGNATURE_ARRAY) ++index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  if (index >= limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  switch (type[index]) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   477
    case JVM_SIGNATURE_BYTE:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   478
    case JVM_SIGNATURE_CHAR:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   479
    case JVM_SIGNATURE_DOUBLE:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   480
    case JVM_SIGNATURE_FLOAT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   481
    case JVM_SIGNATURE_INT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   482
    case JVM_SIGNATURE_LONG:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   483
    case JVM_SIGNATURE_SHORT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   484
    case JVM_SIGNATURE_BOOLEAN:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   485
    case JVM_SIGNATURE_VOID:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
      return index + 1;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   487
    case JVM_SIGNATURE_CLASS:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      for (index = index + 1; index < limit; ++index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
        char c = type[index];
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   490
        switch (c) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   491
          case JVM_SIGNATURE_ENDCLASS:
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   492
            return index + 1;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 54847
diff changeset
   493
          case '\0': case JVM_SIGNATURE_DOT: case JVM_SIGNATURE_ARRAY:
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   494
            return -1;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 54124
diff changeset
   495
          default: ; // fall through
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    default: ; // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
}
54124
5d48ae032588 8219579: Remove redundant signature parsing from the verifier
hseigel
parents: 51997
diff changeset
   503
#endif // ASSERT