ciInstanceKlass.hpp 7.6 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32
#ifndef SHARE_VM_CI_CIINSTANCEKLASS_HPP
#define SHARE_VM_CI_CIINSTANCEKLASS_HPP

#include "ci/ciConstantPoolCache.hpp"
#include "ci/ciFlags.hpp"
#include "ci/ciKlass.hpp"
#include "ci/ciSymbol.hpp"

D
duke 已提交
33 34
// ciInstanceKlass
//
35 36
// This class represents a Klass* in the HotSpot virtual machine
// whose Klass part is an InstanceKlass.  It may or may not
D
duke 已提交
37 38 39
// be loaded.
class ciInstanceKlass : public ciKlass {
  CI_PACKAGE_ACCESS
40
  friend class ciBytecodeStream;
D
duke 已提交
41
  friend class ciEnv;
42
  friend class ciExceptionHandler;
D
duke 已提交
43 44 45 46 47 48 49
  friend class ciMethod;
  friend class ciField;

private:
  jobject                _loader;
  jobject                _protection_domain;

50
  InstanceKlass::ClassState _init_state;           // state of class
51
  bool                   _is_shared;
D
duke 已提交
52 53
  bool                   _has_finalizer;
  bool                   _has_subklass;
54 55
  bool                   _has_nonstatic_fields;

D
duke 已提交
56 57
  ciFlags                _flags;
  jint                   _nonstatic_field_size;
58
  jint                   _nonstatic_oop_map_size;
D
duke 已提交
59 60 61 62 63 64 65 66

  // Lazy fields get filled in only upon request.
  ciInstanceKlass*       _super;
  ciInstance*            _java_mirror;

  ciConstantPoolCache*   _field_cache;  // cached map index->field
  GrowableArray<ciField*>* _nonstatic_fields;

67 68 69 70 71
  // The possible values of the _implementor fall into following three cases:
  //   NULL: no implementor.
  //   A ciInstanceKlass that's not itself: one implementor.
  //   Itsef: more than one implementors.
  ciInstanceKlass*       _implementor;
D
duke 已提交
72

73 74
  GrowableArray<ciField*>* _non_static_fields;

D
duke 已提交
75 76 77 78
protected:
  ciInstanceKlass(KlassHandle h_k);
  ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain);

79 80
  InstanceKlass* get_instanceKlass() const {
    return (InstanceKlass*)get_Klass();
D
duke 已提交
81 82 83 84 85 86 87 88 89 90
  }

  oop loader();
  jobject loader_handle();

  oop protection_domain();
  jobject protection_domain_handle();

  const char* type_string() { return "ciInstanceKlass"; }

91 92
  bool is_in_package_impl(const char* packagename, int len);

D
duke 已提交
93 94 95 96 97 98
  void print_impl(outputStream* st);

  ciConstantPoolCache* field_cache();

  bool is_shared() { return _is_shared; }

99
  void compute_shared_init_state();
D
duke 已提交
100 101 102 103
  bool compute_shared_has_subklass();
  int  compute_nonstatic_fields();
  GrowableArray<ciField*>* compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields);

104
  // Update the init_state for shared klasses
105
  void update_if_shared(InstanceKlass::ClassState expected) {
106 107 108 109 110
    if (_is_shared && _init_state != expected) {
      if (is_loaded()) compute_shared_init_state();
    }
  }

D
duke 已提交
111 112 113
public:
  // Has this klass been initialized?
  bool                   is_initialized() {
114 115
    update_if_shared(InstanceKlass::fully_initialized);
    return _init_state == InstanceKlass::fully_initialized;
116 117 118
  }
  // Is this klass being initialized?
  bool                   is_being_initialized() {
119 120
    update_if_shared(InstanceKlass::being_initialized);
    return _init_state == InstanceKlass::being_initialized;
D
duke 已提交
121 122 123
  }
  // Has this klass been linked?
  bool                   is_linked() {
124 125
    update_if_shared(InstanceKlass::linked);
    return _init_state >= InstanceKlass::linked;
D
duke 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  }

  // General klass information.
  ciFlags                flags()          {
    assert(is_loaded(), "must be loaded");
    return _flags;
  }
  bool                   has_finalizer()  {
    assert(is_loaded(), "must be loaded");
    return _has_finalizer; }
  bool                   has_subklass()   {
    assert(is_loaded(), "must be loaded");
    if (_is_shared && !_has_subklass) {
      if (flags().is_final()) {
        return false;
      } else {
        return compute_shared_has_subklass();
      }
    }
    return _has_subklass;
  }
  jint                   size_helper()  {
    return (Klass::layout_helper_size_in_bytes(layout_helper())
            >> LogHeapWordSize);
  }
  jint                   nonstatic_field_size()  {
    assert(is_loaded(), "must be loaded");
    return _nonstatic_field_size; }
154 155 156
  jint                   has_nonstatic_fields()  {
    assert(is_loaded(), "must be loaded");
    return _has_nonstatic_fields; }
157 158 159
  jint                   nonstatic_oop_map_size()  {
    assert(is_loaded(), "must be loaded");
    return _nonstatic_oop_map_size; }
D
duke 已提交
160
  ciInstanceKlass*       super();
161 162
  jint                   nof_implementors() {
    ciInstanceKlass* impl;
D
duke 已提交
163
    assert(is_loaded(), "must be loaded");
164 165 166 167 168 169 170 171
    impl = implementor();
    if (impl == NULL) {
      return 0;
    } else if (impl != this) {
      return 1;
    } else {
      return 2;
    }
D
duke 已提交
172 173 174 175
  }

  ciInstanceKlass* get_canonical_holder(int offset);
  ciField* get_field_by_offset(int field_offset, bool is_static);
176
  ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static);
177 178 179

  GrowableArray<ciField*>* non_static_fields();

D
duke 已提交
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
  // total number of nonstatic fields (including inherited):
  int nof_nonstatic_fields() {
    if (_nonstatic_fields == NULL)
      return compute_nonstatic_fields();
    else
      return _nonstatic_fields->length();
  }
  // nth nonstatic field (presented by ascending address)
  ciField* nonstatic_field_at(int i) {
    assert(_nonstatic_fields != NULL, "");
    return _nonstatic_fields->at(i);
  }

  ciInstanceKlass* unique_concrete_subklass();
  bool has_finalizable_subclass();

  bool contains_field_offset(int offset) {
197
    return instanceOopDesc::contains_field_offset(offset, nonstatic_field_size());
D
duke 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
  }

  // Get the instance of java.lang.Class corresponding to
  // this klass.  This instance is used for locking of
  // synchronized static methods of this klass.
  ciInstance*            java_mirror();

  // Java access flags
  bool is_public      () { return flags().is_public(); }
  bool is_final       () { return flags().is_final(); }
  bool is_super       () { return flags().is_super(); }
  bool is_interface   () { return flags().is_interface(); }
  bool is_abstract    () { return flags().is_abstract(); }

  ciMethod* find_method(ciSymbol* name, ciSymbol* signature);
  // Note:  To find a method from name and type strings, use ciSymbol::make,
  // but consider adding to vmSymbols.hpp instead.

  bool is_leaf_type();
217
  ciInstanceKlass* implementor();
D
duke 已提交
218 219 220 221

  // Is the defining class loader of this class the default loader?
  bool uses_default_loader();

222
  bool is_java_lang_Object() const;
D
duke 已提交
223

224 225 226 227 228 229
  // Is this klass in the given package?
  bool is_in_package(const char* packagename) {
    return is_in_package(packagename, (int) strlen(packagename));
  }
  bool is_in_package(const char* packagename, int len);

D
duke 已提交
230
  // What kind of ciObject is this?
231 232
  bool is_instance_klass() const { return true; }
  bool is_java_klass() const     { return true; }
D
duke 已提交
233
};
234 235

#endif // SHARE_VM_CI_CIINSTANCEKLASS_HPP