hotspot/src/share/vm/ci/ciObjArrayKlass.cpp
author jrose
Thu, 23 Jun 2011 17:14:06 -0700
changeset 10008 d84de97ad847
parent 8921 14bfe81f2a9d
child 13728 882756847a04
permissions -rw-r--r--
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path Reviewed-by: never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8076
diff changeset
     2
 * Copyright (c) 1999, 2011, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "ci/ciInstanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "ci/ciObjArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "ci/ciObjArrayKlassKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "ci/ciSymbol.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "ci/ciUtilities.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/objArrayKlass.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// ciObjArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// This class represents a klassOop in the HotSpot virtual machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// whose Klass part is an objArrayKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// ciObjArrayKlass::ciObjArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Constructor for loaded object array klasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
ciObjArrayKlass::ciObjArrayKlass(KlassHandle h_k) : ciArrayKlass(h_k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert(get_Klass()->oop_is_objArray(), "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  klassOop element_klassOop = get_objArrayKlass()->bottom_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _base_element_klass = CURRENT_ENV->get_object(element_klassOop)->as_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  assert(_base_element_klass->is_instance_klass() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
         _base_element_klass->is_type_array_klass(), "bad base klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (dimension() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _element_klass = _base_element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    _element_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  if (!ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// ciObjArrayKlass::ciObjArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// Constructor for unloaded object array klasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                                 ciKlass* base_element_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
                                 int dimension)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  : ciArrayKlass(array_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                 dimension,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                 ciObjArrayKlassKlass::make()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    _base_element_klass = base_element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    assert(_base_element_klass->is_instance_klass() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
           _base_element_klass->is_type_array_klass(), "bad base klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    if (dimension == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      _element_klass = base_element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      _element_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// ciObjArrayKlass::element_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// What is the one-level element type of this array?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
ciKlass* ciObjArrayKlass::element_klass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (_element_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    assert(dimension() > 1, "_element_klass should not be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // Produce the element klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    if (is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      klassOop element_klassOop = get_objArrayKlass()->element_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      _element_klass = CURRENT_THREAD_ENV->get_object(element_klassOop)->as_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      // We are an unloaded array klass.  Attempt to fetch our
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      // element klass by name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      _element_klass = CURRENT_THREAD_ENV->get_klass_by_name_impl(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                          this,
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 8921
diff changeset
    96
                          constantPoolHandle(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                          construct_array_name(base_element_klass()->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
                                               dimension() - 1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                          false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  return _element_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
// ciObjArrayKlass::construct_array_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
// Build an array name from an element name and a dimension.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                                                int dimension) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  EXCEPTION_CONTEXT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  int element_len = element_name->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   114
  Symbol* base_name_sym = element_name->get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  char* name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if (base_name_sym->byte_at(0) == '[' ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      (base_name_sym->byte_at(0) == 'L' &&  // watch package name 'Lxx'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
       base_name_sym->byte_at(element_len-1) == ';')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    int new_len = element_len + dimension + 1; // for the ['s and '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    name = CURRENT_THREAD_ENV->name_buffer(new_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    int pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    for ( ; pos < dimension; pos++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      name[pos] = '[';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    strncpy(name+pos, (char*)element_name->base(), element_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    name[new_len-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    int new_len =   3                       // for L, ;, and '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                  + dimension               // for ['s
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                  + element_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    name = CURRENT_THREAD_ENV->name_buffer(new_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    int pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    for ( ; pos < dimension; pos++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      name[pos] = '[';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    name[pos++] = 'L';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    strncpy(name+pos, (char*)element_name->base(), element_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    name[new_len-2] = ';';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    name[new_len-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  return ciSymbol::make(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// ciObjArrayKlass::make_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// Implementation of make.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  if (element_klass->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    EXCEPTION_CONTEXT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    // The element klass is loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    klassOop array = element_klass->get_Klass()->array_klass(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      CURRENT_THREAD_ENV->record_out_of_memory_failure();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      return ciEnv::unloaded_ciobjarrayklass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    return CURRENT_THREAD_ENV->get_object(array)->as_obj_array_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // The array klass was unable to be made or the element klass was
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // not loaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  if (array_name == ciEnv::unloaded_cisymbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    return ciEnv::unloaded_ciobjarrayklass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
                        ->as_obj_array_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// ciObjArrayKlass::make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
// Make an array klass corresponding to the specified primitive type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  assert(element_klass->is_java_klass(), "wrong kind of klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  GUARDED_VM_ENTRY(return make_impl(element_klass);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}