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