src/hotspot/share/runtime/fieldType.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
/*
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 51997
diff changeset
    26
#include "classfile/symbolTable.hpp"
7397
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: 8921
diff changeset
    29
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/typeArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/fieldType.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/signature.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    35
BasicType FieldType::basic_type(Symbol* signature) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
    36
  return char2type(signature->char_at(0));
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
// Check if it is a valid array signature
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    40
bool FieldType::is_valid_array_signature(Symbol* sig) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  assert(sig->utf8_length() > 1, "this should already have been checked");
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
    42
  assert(sig->char_at(0) == JVM_SIGNATURE_ARRAY, "this should already have been checked");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // The first character is already checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  int i = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int len = sig->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // First skip all '['s
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
    47
  while(i < len - 1 && sig->char_at(i) == JVM_SIGNATURE_ARRAY) i++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Check type
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49354
diff changeset
    50
  switch(sig->char_at(i)) {
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
    51
    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
    52
    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
    53
    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
    54
    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
    55
    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
    56
    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
    57
    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
    58
    case JVM_SIGNATURE_BOOLEAN:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      // If it is an array, the type is the last character
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      return (i + 1 == len);
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
    61
    case JVM_SIGNATURE_CLASS:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      // If it is an object, the last character must be a ';'
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
    63
      return sig->char_at(len - 1) == JVM_SIGNATURE_ENDCLASS;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
BasicType FieldType::get_array_info(Symbol* signature, FieldArrayInfo& fd, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  assert(basic_type(signature) == T_ARRAY, "must be array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  int index = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  int dim   = 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
    74
  while (signature->char_at(index) == JVM_SIGNATURE_ARRAY) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    dim++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  ResourceMark rm;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    79
  char *element = signature->as_C_string() + index;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    80
  BasicType element_type = char2type(element[0]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (element_type == T_OBJECT) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    82
    int len = (int)strlen(element);
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
    83
    assert(element[len-1] == JVM_SIGNATURE_ENDCLASS, "last char should be a semicolon");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    84
    element[len-1] = '\0';        // chop off semicolon
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
    85
    fd._object_key = SymbolTable::new_symbol(element + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Pass dimension back to caller
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    88
  fd._dimension = dim;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  return element_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}