hotspot/src/share/vm/runtime/fieldType.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
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-2000 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/_fieldType.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
void FieldType::skip_optional_size(symbolOop signature, int* index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  jchar c = signature->byte_at(*index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  while (c >= '0' && c <= '9') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
    *index = *index + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
    c = signature->byte_at(*index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
BasicType FieldType::basic_type(symbolOop signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  return char2type(signature->byte_at(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// Check if it is a valid array signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
bool FieldType::is_valid_array_signature(symbolOop sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  assert(sig->utf8_length() > 1, "this should already have been checked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert(sig->byte_at(0) == '[', "this should already have been checked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // The first character is already checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int i = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  int len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // First skip all '['s
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  while(i < len - 1 && sig->byte_at(i) == '[') i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // Check type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  switch(sig->byte_at(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    case 'B': // T_BYTE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    case 'C': // T_CHAR
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    case 'D': // T_DOUBLE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    case 'F': // T_FLOAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    case 'I': // T_INT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    case 'J': // T_LONG
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    case 'S': // T_SHORT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    case 'Z': // T_BOOLEAN
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      // If it is an array, the type is the last character
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      return (i + 1 == len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    case 'L':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      // If it is an object, the last character must be a ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      return sig->byte_at(len - 1) == ';';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
BasicType FieldType::get_array_info(symbolOop signature, jint* dimension, symbolOop* object_key, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  assert(basic_type(signature) == T_ARRAY, "must be array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  int index = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  int dim   = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  skip_optional_size(signature, &index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  while (signature->byte_at(index) == '[') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    dim++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    skip_optional_size(signature, &index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  symbolOop element = oopFactory::new_symbol(signature->as_C_string() + index, CHECK_(T_BYTE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  BasicType element_type = FieldType::basic_type(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  if (element_type == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    char* object_type = element->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    object_type[element->utf8_length() - 1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    *object_key = oopFactory::new_symbol(object_type + 1, CHECK_(T_BYTE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Pass dimension back to caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  *dimension = dim;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  return element_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}