hotspot/src/share/vm/classfile/vmSymbols.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 218 a0e996680b05
permissions -rw-r--r--
Initial load
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/_vmSymbols.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
symbolOop vmSymbols::_symbols[vmSymbols::SID_LIMIT];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
symbolOop vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
inline int compare_symbol(symbolOop a, symbolOop b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  if (a == b)  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // follow the natural address order:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  return (address)a > (address)b ? +1 : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  static int compare_vmsymbol_sid(const void* void_a, const void* void_b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    symbolOop a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    symbolOop b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    return compare_symbol(a, b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
#define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
static const char* vm_symbol_enum_names =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  "\0";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
static const char* vm_symbol_enum_name(vmSymbols::SID sid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  const char* string = &vm_symbol_enum_names[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  int skip = (int)sid - (int)vmSymbols::FIRST_SID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  for (; skip != 0; skip--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    size_t skiplen = strlen(string);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (skiplen == 0)  return "<unknown>";  // overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    string += skiplen+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  return string;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// Put all the VM symbol strings in one place.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// Makes for a more compact libjvm.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
#define VM_SYMBOL_BODY(name, string) string "\0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
void vmSymbols::initialize(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (!UseSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    const char* string = &vm_symbol_bodies[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      symbolOop sym = oopFactory::new_symbol(string, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      _symbols[index] = sym;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      string += strlen(string); // skip string body
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      string += 1;              // skip trailing null
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    _type_signatures[T_BYTE]    = byte_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    _type_signatures[T_CHAR]    = char_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _type_signatures[T_DOUBLE]  = double_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    _type_signatures[T_FLOAT]   = float_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    _type_signatures[T_INT]     = int_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    _type_signatures[T_LONG]    = long_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    _type_signatures[T_SHORT]   = short_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    _type_signatures[T_BOOLEAN] = bool_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    _type_signatures[T_VOID]    = void_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // no single signatures for T_OBJECT or T_ARRAY
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Check for duplicates:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    symbolOop sym = symbol_at((SID)i1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    for (int i2 = (int)FIRST_SID; i2 < i1; i2++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      if (symbol_at((SID)i2) == sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                   vm_symbol_enum_name((SID)i2), i2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                   vm_symbol_enum_name((SID)i1), i1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        sym->print_symbol_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        tty->print_cr("\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
#endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Create an index for find_id:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      vm_symbol_index[index] = (SID)index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    int num_sids = SID_LIMIT-FIRST_SID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
          compare_vmsymbol_sid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // Spot-check correspondence between strings, symbols, and enums:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    assert(_symbols[NO_SID] == NULL, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    const char* str = "java/lang/Object";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    symbolOop sym = oopFactory::new_symbol(str, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    assert(strcmp(str, (char*)sym->base()) == 0, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    assert(sym == java_lang_Object(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    SID sid = VM_SYMBOL_ENUM_NAME(java_lang_Object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    assert(find_sid(sym) == sid, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    assert(symbol_at(sid) == sym, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // Make sure find_sid produces the right answer in each case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      sym = symbol_at((SID)index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      sid = find_sid(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      assert(sid == (SID)index, "symbol index works");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      // Note:  If there are duplicates, this assert will fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      // A "Duplicate VM symbol" message will have already been printed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    // The string "format" happens (at the moment) not to be a vmSymbol,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    // though it is a method name in java.lang.String.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    str = "format";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    sym = oopFactory::new_symbol(str, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    sid = find_sid(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    assert(sid == NO_SID, "symbol index works (negative test)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
const char* vmSymbols::name_for(vmSymbols::SID sid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  if (sid == NO_SID)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return "NO_SID";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  const char* string = &vm_symbol_bodies[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    if (index == (int)sid)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      return string;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    string += strlen(string); // skip string body
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    string += 1;              // skip trailing null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  return "BAD_SID";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
void vmSymbols::oops_do(OopClosure* f, bool do_all) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    f->do_oop((oop*) &_symbols[index]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  for (int i = 0; i < T_VOID+1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    if (_type_signatures[i] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      assert(i >= T_BOOLEAN, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      f->do_oop((oop*)&_type_signatures[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    } else if (do_all) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      f->do_oop((oop*)&_type_signatures[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
BasicType vmSymbols::signature_type(symbolOop s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  assert(s != NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    if (s == _type_signatures[i]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      return (BasicType)i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  return T_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
static int mid_hint = (int)vmSymbols::FIRST_SID+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
static int find_sid_calls, find_sid_probes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
// (Typical counts are calls=7000 and probes=17000.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
vmSymbols::SID vmSymbols::find_sid(symbolOop symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // Handle the majority of misses by a bounds check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  // Then, use a binary search over the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // Expected trip count is less than log2_SID_LIMIT, about eight.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // This is slow but acceptable, given that calls are not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // dynamically common.  (methodOop::intrinsic_id has a cache.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  NOT_PRODUCT(find_sid_calls++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  int min = (int)FIRST_SID, max = (int)SID_LIMIT - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  SID sid = NO_SID, sid1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  int cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  sid1 = vm_symbol_index[min];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  cmp1 = compare_symbol(symbol, symbol_at(sid1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  if (cmp1 <= 0) {              // before the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    if (cmp1 == 0)  sid = sid1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    sid1 = vm_symbol_index[max];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    cmp1 = compare_symbol(symbol, symbol_at(sid1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    if (cmp1 >= 0) {            // after the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      if (cmp1 == 0)  sid = sid1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      // After checking the extremes, do a binary search.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      ++min; --max;             // endpoints are done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      int mid = mid_hint;       // start at previous success
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      while (max >= min) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        assert(mid >= min && mid <= max, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        NOT_PRODUCT(find_sid_probes++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        sid1 = vm_symbol_index[mid];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        cmp1 = compare_symbol(symbol, symbol_at(sid1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        if (cmp1 == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          mid_hint = mid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
          sid = sid1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        if (cmp1 < 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
          max = mid - 1;        // symbol < symbol_at(sid)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
          min = mid + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        // Pick a new probe point:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        mid = (max + min) / 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Perform the exhaustive self-check the first 1000 calls,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // and every 100 calls thereafter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  static int find_sid_check_count = -2000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  if ((uint)++find_sid_check_count > (uint)100) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    if (find_sid_check_count > 0)  find_sid_check_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    // Make sure this is the right answer, using linear search.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    // (We have already proven that there are no duplicates in the list.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    SID sid2 = NO_SID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      symbolOop sym2 = symbol_at((SID)index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      if (sym2 == symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        sid2 = (SID)index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    // Unless it's a duplicate, assert that the sids are the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    if (_symbols[sid] != _symbols[sid2]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      assert(sid == sid2, "binary same as linear search");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
#endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  return sid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
#define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
static const char* vm_intrinsic_name_bodies =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
                   VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
static const char* vm_intrinsic_name_table[vmIntrinsics::ID_LIMIT];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
const char* vmIntrinsics::name_at(vmIntrinsics::ID id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  const char** nt = &vm_intrinsic_name_table[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  if (nt[_none] == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    char* string = (char*) &vm_intrinsic_name_bodies[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    for (int index = FIRST_ID; index < ID_LIMIT; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      nt[index] = string;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      string += strlen(string); // skip string body
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      string += 1;              // skip trailing null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    assert(!strcmp(nt[_hashCode], "_hashCode"), "lined up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    nt[_none] = "_none";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  if ((uint)id < (uint)ID_LIMIT)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    return vm_intrinsic_name_table[(uint)id];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    return "(unknown intrinsic)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
// These are flag-matching functions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
inline bool match_F_R(jshort flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  const int req = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  return (flags & (req | neg)) == req;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
inline bool match_F_RN(jshort flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  const int req = JVM_ACC_NATIVE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  return (flags & (req | neg)) == req;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
inline bool match_F_S(jshort flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  const int req = JVM_ACC_STATIC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  const int neg = JVM_ACC_SYNCHRONIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  return (flags & (req | neg)) == req;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
inline bool match_F_SN(jshort flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  const int req = JVM_ACC_STATIC | JVM_ACC_NATIVE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  const int neg = JVM_ACC_SYNCHRONIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  return (flags & (req | neg)) == req;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// These are for forming case labels:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
#define ID3(x, y, z) (( jint)(z) +                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
                      ((jint)(y) <<    vmSymbols::log2_SID_LIMIT) + \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
                      ((jint)(x) << (2*vmSymbols::log2_SID_LIMIT))  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
#define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
vmIntrinsics::ID vmIntrinsics::find_id(vmSymbols::SID holder,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
                                       vmSymbols::SID name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
                                       vmSymbols::SID sig,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                                       jshort flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  // Let the C compiler build the decision tree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  case ID3(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig)): \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    if (!match_##fcode(flags))  break; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    return id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  switch (ID3(holder, name, sig)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
                     VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  return vmIntrinsics::_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
#undef VM_INTRINSIC_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  const char* str = name_at(id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  const char* kname = vmSymbols::name_for(class_for(id));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  const char* mname = vmSymbols::name_for(name_for(id));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  const char* sname = vmSymbols::name_for(signature_for(id));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  const char* fname = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  switch (flags_for(id)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  case F_RN: fname = "native ";        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  case F_SN: fname = "native static "; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  case F_S:  fname = "static ";        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  const char* kptr = strrchr(kname, '/');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  if (kptr != NULL)  kname = kptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  int len = jio_snprintf(buf, buflen, "%s: %s%s.%s%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                         str, fname, kname, mname, sname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  if (len < buflen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    str = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// These are for friendly printouts of intrinsics:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  case id: return SID_ENUM(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  switch (id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
                     VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
#undef VM_INTRINSIC_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  return vmSymbols::NO_SID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  case id: return SID_ENUM(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  switch (id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
                     VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
#undef VM_INTRINSIC_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  return vmSymbols::NO_SID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  case id: return SID_ENUM(sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  switch (id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
                     VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
#undef VM_INTRINSIC_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  return vmSymbols::NO_SID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  case id: return fcode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  switch (id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
                     VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
#undef VM_INTRINSIC_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  return F_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
// verify_method performs an extra check on a matched intrinsic method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
static bool match_method(methodOop m, symbolOop n, symbolOop s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  return (m->name() == n &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
          m->signature() == s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
static vmIntrinsics::ID match_method_with_klass(methodOop m, symbolOop mk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
#define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  { symbolOop k = vmSymbols::klassname(); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    if (mk == k) { \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      symbolOop n = vmSymbols::namepart(); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      symbolOop s = vmSymbols::sigpart(); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      if (match_method(m, n, s)) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        return vmIntrinsics::id; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    } }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  VM_INTRINSICS_DO(VM_INTRINSIC_MATCH,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
                   VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  return vmIntrinsics::_none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
#undef VM_INTRINSIC_MATCH
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
void vmIntrinsics::verify_method(ID actual_id, methodOop m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  symbolOop mk = Klass::cast(m->method_holder())->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  ID declared_id = match_method_with_klass(m, mk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  if (declared_id == actual_id)  return; // success
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  if (declared_id == _none && actual_id != _none && mk == vmSymbols::java_lang_StrictMath()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    // Here are a few special cases in StrictMath not declared in vmSymbols.hpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    switch (actual_id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    case _min:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    case _max:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    case _dsqrt:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      if (declared_id == actual_id)  return; // acceptable alias
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  const char* declared_name = name_at(declared_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  const char* actual_name   = name_at(actual_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  methodHandle mh = m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  m = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  ttyLocker ttyl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  if (xtty != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
                     actual_name, declared_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    xtty->method(mh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    xtty->end_elem("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  if (PrintMiscellaneous && (WizardMode || Verbose)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    tty->print_cr("*** misidentified method; %s(%d) should be %s(%d):",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                  declared_name, declared_id, actual_name, actual_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    m->print_short_name(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
#endif //PRODUCT