hotspot/src/share/vm/classfile/systemDictionary.cpp
author twisti
Mon, 04 Jan 2010 18:38:08 +0100
changeset 4564 55dfb20908d0
parent 4446 73f83d9d3e9c
child 4571 80b553bddc26
permissions -rw-r--r--
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164) Summary: During the work for 6829187 we have fixed a number of basic bugs which are logically grouped with 6815692 and 6858164 but which must be reviewed and pushed separately. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 2034
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  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
 *
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/_systemDictionary.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
Dictionary*       SystemDictionary::_dictionary = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
PlaceholderTable* SystemDictionary::_placeholders = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
Dictionary*       SystemDictionary::_shared_dictionary = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
    34
SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
int         SystemDictionary::_number_of_modifications = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
    41
klassOop    SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
    42
                                                          =  { NULL /*, NULL...*/ };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
klassOop    SystemDictionary::_box_klasses[T_VOID+1]      =  { NULL /*, NULL...*/ };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
oop         SystemDictionary::_java_system_loader         =  NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
bool        SystemDictionary::_has_loadClassInternal      =  false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
bool        SystemDictionary::_has_checkPackageAccess     =  false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// lazily initialized klass variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
volatile klassOop    SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// Java-level SystemLoader
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
oop SystemDictionary::java_system_loader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  return _java_system_loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
void SystemDictionary::compute_java_system_loader(TRAPS) {
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
    63
  KlassHandle system_klass(THREAD, WK_KLASS(classloader_klass));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  JavaValue result(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  JavaCalls::call_static(&result,
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
    66
                         KlassHandle(THREAD, WK_KLASS(classloader_klass)),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                         vmSymbolHandles::getSystemClassLoader_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                         vmSymbolHandles::void_classloader_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                         CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _java_system_loader = (oop)result.get_jobject();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// return true if class_name contains no '.' (internal format is '/')
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
bool SystemDictionary::is_internal_format(symbolHandle class_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if (class_name.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    char* name = class_name->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return strchr(name, '.') == NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// ----------------------------------------------------------------------------
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
    94
// Parallel class loading check
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
    95
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
    96
bool SystemDictionary::is_parallelCapable(Handle class_loader) {
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
    97
  if (UnsyncloadClass || class_loader.is_null()) return true;
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
    98
  if (AlwaysLockClassLoader) return false;
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
    99
  return java_lang_Class::parallelCapable(class_loader());
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   100
}
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   101
// ----------------------------------------------------------------------------
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   102
// ParallelDefineClass flag does not apply to bootclass loader
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   103
bool SystemDictionary::is_parallelDefine(Handle class_loader) {
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   104
   if (class_loader.is_null()) return false;
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   105
   if (AllowParallelDefineClass && java_lang_Class::parallelCapable(class_loader())) {
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   106
     return true;
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   107
   }
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   108
   return false;
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   109
}
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   110
// ----------------------------------------------------------------------------
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
// Resolving of classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// Forwards to resolve_or_null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if (HAS_PENDING_EXCEPTION || klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    KlassHandle k_h(THREAD, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    // can return a null klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  return klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
klassOop SystemDictionary::handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    // If we have a pending exception we forward it to the caller, unless throw_error is true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    // in which case we have to check whether the pending exception is a ClassNotFoundException,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    // and if so convert it to a NoClassDefFoundError
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // And chain the original ClassNotFoundException
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::classNotFoundException_klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      assert(klass_h() == NULL, "Should not have result with exception pending");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      Handle e(THREAD, PENDING_EXCEPTION);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Class not found, throw appropriate error or exception depending on value of throw_error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  if (klass_h() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (throw_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  return (klassOop)klass_h();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                                           bool throw_error, TRAPS)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// Forwards to resolve_instance_class_or_null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if (FieldType::is_array(class_name())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
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
klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return resolve_or_null(class_name, Handle(), Handle(), THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// Forwards to resolve_instance_class_or_null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
klassOop SystemDictionary::resolve_array_class_or_null(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
                                                       Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                                                       Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                                                       TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  assert(FieldType::is_array(class_name()), "must be array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  jint dimension;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  symbolOop object_key;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  klassOop k = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // dimension and object_key are assigned as a side-effect of this call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  BasicType t = FieldType::get_array_info(class_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                                          &dimension,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
                                          &object_key,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                                          CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  if (t == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    symbolHandle h_key(THREAD, object_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // naked oop "k" is OK here -- we assign back into it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    k = SystemDictionary::resolve_instance_class_or_null(h_key,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                                                         class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                                                         protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                                                         CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      k = Klass::cast(k)->array_klass(dimension, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    k = Universe::typeArrayKlassObj(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    k = typeArrayKlass::cast(k)->array_klass(dimension, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// Must be called for any super-class or super-interface resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
// during class definition to allow class circularity checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// super-interface callers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
//    parse_interfaces - for defineClass & jvmtiRedefineClasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// super-class callers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
//   ClassFileParser - for defineClass & jvmtiRedefineClasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
//   load_shared_class - while loading a class from shared archive
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   217
//   resolve_instance_class_or_null:
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   218
//     via: handle_parallel_super_load
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
//      when resolving a class that has an existing placeholder with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
//      a saved superclass [i.e. a defineClass is currently in progress]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
//      if another thread is trying to resolve the class, it must do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
//      super-class checks on its own thread to catch class circularity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// This last call is critical in class circularity checking for cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// where classloading is delegated to different threads and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
// classloader lock is released.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// Take the case: Base->Super->Base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
//   1. If thread T1 tries to do a defineClass of class Base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
//    resolve_super_or_fail creates placeholder: T1, Base (super Super)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
//   2. resolve_instance_class_or_null does not find SD or placeholder for Super
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
//    so it tries to load Super
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
//   3. If we load the class internally, or user classloader uses same thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
//      loadClassFromxxx or defineClass via parseClassFile Super ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
//      3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
//      3.3 resolve_instance_class_or_null Base, finds placeholder for Base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
//      3.4 calls resolve_super_or_fail Base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
//      3.5 finds T1,Base -> throws class circularity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
//OR 4. If T2 tries to resolve Super via defineClass Super ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
//      4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
//      4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
//      4.3 calls resolve_super_or_fail Super in parallel on own thread T2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
//      4.4 finds T2, Super -> throws class circularity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// Must be called, even if superclass is null, since this is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// where the placeholder entry is created which claims this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// thread is loading this class/classloader.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
                                                 symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
                                                 Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
                                                 Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                                                 bool is_superclass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                                                 TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   252
  // Try to get one of the well-known klasses.
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   253
  // They are trusted, and do not participate in circularities.
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   254
  if (LinkWellKnownClasses) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   255
    klassOop k = find_well_known_klass(class_name());
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   256
    if (k != NULL) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   257
      return k;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   258
    }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   259
  }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   260
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // Double-check, if child class is already loaded, just return super-class,interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // Don't add a placedholder if already loaded, i.e. already in system dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // Make sure there's a placeholder for the *child* before resolving.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // Used as a claim that this thread is currently loading superclass/classloader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // Used here for ClassCircularity checks and also for heap verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // (every instanceKlass in the heap needs to be in the system dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // or have a placeholder).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // Must check ClassCircularity before checking if super class is already loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // We might not already have a placeholder if this child_name was
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // the name of the class might not be known until the stream is actually
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  // parsed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // Bugs 4643874, 4715493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // compute_hash can have a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  // can't throw error holding a lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  bool child_already_loaded = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  bool throw_circularity_error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    klassOop childk = find_class(d_index, d_hash, child_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    klassOop quicksuperk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    // to support // loading: if child done loading, just return superclass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    // if class_name, & class_loader don't match:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    // if initial define, SD update will give LinkageError
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    // if redefine: compare_class_versions will give HIERARCHY_CHANGED
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    // so we don't throw an exception here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    // see: nsk redefclass014 & java.lang.instrument Instrument032
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    if ((childk != NULL ) && (is_superclass) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
       ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
         ((Klass::cast(quicksuperk)->name() == class_name()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
            (Klass::cast(quicksuperk)->class_loader()  == class_loader()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
           return quicksuperk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
          throw_circularity_error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      }
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   305
    }
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   306
    if (!throw_circularity_error) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  if (throw_circularity_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
// java.lang.Object should have been found above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  assert(class_name() != NULL, "null super class for resolving");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Resolve the super class or interface, check results on return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  klassOop superk = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  superk = SystemDictionary::resolve_or_null(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                                                 class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
                                                 protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
                                                 THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  KlassHandle superk_h(THREAD, superk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  // Note: clean up of placeholders currently in callers of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // resolve_super_or_fail - either at update_dictionary time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // or on error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
   PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
   if (probe != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    // can null superk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  return superk_h();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
                                                  Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
                                                  Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                                                  TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  if(!has_checkPackageAccess()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // Now we have to call back to java to check if the initating class has access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  if (TraceProtectionDomainVerification) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    // Print out trace information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    tty->print_cr("Checking package access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    tty->print(" - class loader:      "); class_loader()->print_value_on(tty);      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    tty->print(" - loading:           "); klass()->print_value_on(tty);             tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  assert(class_loader() != NULL, "should not have non-null protection domain for null classloader");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  KlassHandle system_loader(THREAD, SystemDictionary::classloader_klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
                         class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
                         system_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                         vmSymbolHandles::checkPackageAccess_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
                         vmSymbolHandles::class_protectiondomain_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
                         Handle(THREAD, klass->java_mirror()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
                         protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                         THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  if (TraceProtectionDomainVerification) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
     tty->print_cr(" -> granted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  if (HAS_PENDING_EXCEPTION) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  // If no exception has been thrown, we have validated the protection domain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // Insert the protection domain of the initiating class into the set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    // We recalculate the entry here -- we've called out to java since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    // the last time it was calculated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    symbolHandle kn(THREAD, klass->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    unsigned int d_hash = dictionary()->compute_hash(kn, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      // Note that we have an entry, and entries can be deleted only during GC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      // so we cannot allow GC to occur while we're holding this entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      // We're using a No_Safepoint_Verifier to catch any place where we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      // might potentially do a GC at all.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      // SystemDictionary::do_unloading() asserts that classes are only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      // unloaded at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      No_Safepoint_Verifier nosafepoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
                                          protection_domain, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
// We only get here if this thread finds that another thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
// has already claimed the placeholder token for the current operation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
// but that other thread either never owned or gave up the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// object lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
// Waits on SystemDictionary_lock to indicate placeholder table updated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
// On return, caller must recheck placeholder table state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
// We only get here if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
//  1) custom classLoader, i.e. not bootstrap classloader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
//  2) UnsyncloadClass not set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
//  3) custom classLoader has broken the class loader objectLock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
//     so another thread got here in parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
// lockObject must be held.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
// Complicated dance due to lock ordering:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
// Must first release the classloader object lock to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
// allow initial definer to complete the class definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
// and to avoid deadlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
// Reclaim classloader lock object with same original recursion count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
// Must release SystemDictionary_lock after notify, since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// class loader lock must be claimed before SystemDictionary_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// to prevent deadlocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
// The notify allows applications that did an untimed wait() on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
// the classloader object lock to not hang.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  assert_lock_strong(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  bool calledholdinglock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  assert(calledholdinglock,"must hold lock for notify");
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   439
  assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  ObjectSynchronizer::notifyall(lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  intptr_t recursions =  ObjectSynchronizer::complete_exit(lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  SystemDictionary_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  SystemDictionary_lock->unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  SystemDictionary_lock->lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
// If the class in is in the placeholder table, class loading is in progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
// For cases where the application changes threads to load classes, it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
// is critical to ClassCircularity detection that we try loading
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
// the superclass on the same thread internally, so we do parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
// super class loading here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
// This also is critical in cases where the original thread gets stalled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
// even in non-circularity situations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
// Note: only one thread can define the class, but multiple can resolve
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
// Note: must call resolve_super_or_fail even if null super -
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   457
// to force placeholder entry creation for this class for circularity detection
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
// Caller must check for pending exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
// Returns non-null klassOop if other thread has completed load
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
// and we are done,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
// If return null klassOop and no pending exception, the caller must load the class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
instanceKlassHandle SystemDictionary::handle_parallel_super_load(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    symbolHandle name, symbolHandle superclassname, Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    Handle protection_domain, Handle lockObject, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  // superk is not used, resolve_super called for circularity check only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  // This code is reached in two situations. One if this thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  // is loading the same class twice (e.g. ClassCircularity, or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  // java.lang.instrument).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  // The second is if another thread started the resolve_super first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  // and has not yet finished.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  // In both cases the original caller will clean up the placeholder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  // entry on error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  klassOop superk = SystemDictionary::resolve_super_or_fail(name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
                                                          superclassname,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
                                                          class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
                                                          protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
                                                          true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
                                                          CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  // We don't redefine the class, so we just need to clean up if there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  // was not an error (don't want to modify any system dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  // data structures).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   495
  // parallelCapable class loaders do NOT wait for parallel superclass loads to complete
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   496
  // Serial class loaders and bootstrap classloader do wait for superclass loads
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   497
 if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    // Check if classloading completed while we were loading superclass or waiting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    if (check != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
      // Klass is already loaded, so just return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
      return(instanceKlassHandle(THREAD, check));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
      return nh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  // must loop to both handle other placeholder updates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  // and spurious notifications
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  bool super_load_in_progress = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  PlaceholderEntry* placeholder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  while (super_load_in_progress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    // Check if classloading completed while we were loading superclass or waiting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    if (check != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      // Klass is already loaded, so just return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      return(instanceKlassHandle(THREAD, check));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
      if (placeholder && placeholder->super_load_in_progress() ){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
        // Before UnsyncloadClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
        // We only get here if the application has released the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
        // classloader lock when another thread was in the middle of loading a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
        // superclass/superinterface for this class, and now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
        // this thread is also trying to load this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
        // To minimize surprises, the first thread that started to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
        // load a class should be the one to complete the loading
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
        // with the classfile it initially expected.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        // This logic has the current thread wait once it has done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
        // all the superclass/superinterface loading it can, until
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
        // the original thread completes the class loading or fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
        // If it completes we will use the resulting instanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
        // which we will find below in the systemDictionary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
        // We also get here for parallel bootstrap classloader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
        if (class_loader.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
          SystemDictionary_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
          double_lock_wait(lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        // If not in SD and not in PH, other thread's load must have failed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        super_load_in_progress = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  return (nh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
klassOop SystemDictionary::resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  assert(class_name.not_null() && !FieldType::is_array(class_name()), "invalid class name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  // First check to see if we should remove wrapping L and ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  symbolHandle name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  if (FieldType::is_obj(class_name())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    // Ignore wrapping L and ;.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    name = oopFactory::new_symbol_handle(class_name()->as_C_string() + 1, class_name()->utf8_length() - 2, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    name = class_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  // UseNewReflection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  // Fix for 4474172; see evaluation for more details
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // Do lookup to see if class already exist and the protection domain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // has the right access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
                                      protection_domain, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  if (probe != NULL) return probe;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  // Non-bootstrap class loaders will call out to class loader and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  // define via jvm/jni_DefineClass which will acquire the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  // class loader object lock to protect against multiple threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  // defining the class in parallel by accident.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  // This lock must be acquired here so the waiter will find
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // any successful result in the SystemDictionary and not attempt
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  // the define
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   584
  // ParallelCapable Classloaders and the bootstrap classloader,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  // or all classloaders with UnsyncloadClass do not acquire lock here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  bool DoObjectLock = true;
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   587
  if (is_parallelCapable(class_loader)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    DoObjectLock = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  // Class is not in SystemDictionary so we have to do loading.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  // Make sure we are synchronized on the class loader before we proceed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  check_loader_lock_contention(lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  ObjectLocker ol(lockObject, THREAD, DoObjectLock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  // Check again (after locking) if class already exist in SystemDictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  bool class_has_been_loaded   = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  bool super_load_in_progress  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  bool havesupername = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  instanceKlassHandle k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  PlaceholderEntry* placeholder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  symbolHandle superclassname;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    if (check != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      // Klass is already loaded, so just return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
      class_has_been_loaded = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
      k = instanceKlassHandle(THREAD, check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
      placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
      if (placeholder && placeholder->super_load_in_progress()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
         super_load_in_progress = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
         if (placeholder->havesupername() == true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
           superclassname = symbolHandle(THREAD, placeholder->supername());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
           havesupername = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  // If the class in is in the placeholder table, class loading is in progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  if (super_load_in_progress && havesupername==true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    k = SystemDictionary::handle_parallel_super_load(name, superclassname,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
        class_loader, protection_domain, lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    if (!k.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
      class_has_been_loaded = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  if (!class_has_been_loaded) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    // add placeholder entry to record loading instance class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    // Five cases:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    // All cases need to prevent modifying bootclasssearchpath
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    // in parallel with a classload of same classname
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   645
    // Redefineclasses uses existence of the placeholder for the duration
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   646
    // of the class load to prevent concurrent redefinition of not completely
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   647
    // defined classes.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    // case 1. traditional classloaders that rely on the classloader object lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    //   - no other need for LOAD_INSTANCE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    // case 2. traditional classloaders that break the classloader object lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    //    as a deadlock workaround. Detection of this case requires that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    //    this check is done while holding the classloader object lock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    //    and that lock is still held when calling classloader's loadClass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    //    For these classloaders, we ensure that the first requestor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    //    completes the load and other requestors wait for completion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    // case 3. UnsyncloadClass - don't use objectLocker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    //    With this flag, we allow parallel classloading of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    //    class/classloader pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    // case4. Bootstrap classloader - don't own objectLocker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    //    This classloader supports parallelism at the classloader level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    //    but only allows a single load of a class/classloader pair.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    //    No performance benefit and no deadlock issues.
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   663
    // case 5. parallelCapable user level classloaders - without objectLocker
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   664
    //    Allow parallel classloading of a class/classloader pair
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    symbolHandle nullsymbolHandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    bool throw_circularity_error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      MutexLocker mu(SystemDictionary_lock, THREAD);
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   669
      if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
        PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
        if (oldprobe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
          // only need check_seen_thread once, not on each loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
          // 6341374 java/lang/Instrument with -Xcomp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
          if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
            throw_circularity_error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
            // case 1: traditional: should never see load_in_progress.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
            while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
              // case 4: bootstrap classloader: prevent futile classloading,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
              // wait on first requestor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
              if (class_loader.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
                SystemDictionary_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
              // case 2: traditional with broken classloader lock. wait on first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
              // requestor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
                double_lock_wait(lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
              // Check if classloading completed while we were waiting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
              klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
              if (check != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
                // Klass is already loaded, so just return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
                k = instanceKlassHandle(THREAD, check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
                class_has_been_loaded = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
              // check if other thread failed to load and cleaned up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
              oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
      // All cases: add LOAD_INSTANCE
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   703
      // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
      // LOAD_INSTANCE in parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
      // add placeholder entry even if error - callers will remove on error
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   706
      if (!throw_circularity_error && !class_has_been_loaded) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
        PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, nullsymbolHandle, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
        // For class loaders that do not acquire the classloader object lock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
        // if they did not catch another thread holding LOAD_INSTANCE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
        // need a check analogous to the acquire ObjectLocker/find_class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
        // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
        // one final check if the load has already completed
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   713
        // class loaders holding the ObjectLock shouldn't find the class here
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
        klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
        if (check != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
        // Klass is already loaded, so just return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
          k = instanceKlassHandle(THREAD, check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
          class_has_been_loaded = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
          newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   720
          placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   721
          SystemDictionary_lock->notify_all();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    // must throw error outside of owning lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    if (throw_circularity_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
      ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    if (!class_has_been_loaded) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
      // Do actual loading
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      k = load_instance_class(name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   736
      // For UnsyncloadClass only
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      // If they got a linkageError, check if a parallel class load succeeded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
      // If it did, then for bytecode resolution the specification requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      // that we return the same result we did for the other thread, i.e. the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
      // successfully loaded instanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      // Should not get here for classloaders that support parallelism
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
   742
      // with the new cleaner mechanism, even with AllowParallelDefineClass
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   743
      // Bootstrap goes through here to allow for an extra guarantee check
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
      if (UnsyncloadClass || (class_loader.is_null())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
        if (k.is_null() && HAS_PENDING_EXCEPTION
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
          && PENDING_EXCEPTION->is_a(SystemDictionary::linkageError_klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
          MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
          klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
          if (check != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
            // Klass is already loaded, so just use it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
            k = instanceKlassHandle(THREAD, check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
            CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
            guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
      // clean up placeholder entries for success or error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      // This cleans up LOAD_INSTANCE entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
      // It also cleans up LOAD_SUPER entries on errors from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
      // calling load_instance_class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
        PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
        if (probe != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
          probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
          placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
          SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
      // If everything was OK (no exceptions, no null return value), and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      // class_loader is NOT the defining loader, do a little more bookkeeping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
      if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
        k->class_loader() != class_loader()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
        check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
        // Need to check for a PENDING_EXCEPTION again; check_constraints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
        // can throw and doesn't use the CHECK macro.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
        if (!HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
          { // Grabbing the Compile_lock prevents systemDictionary updates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
            // during compilations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
            MutexLocker mu(Compile_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
            update_dictionary(d_index, d_hash, p_index, p_hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
                            k, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
          if (JvmtiExport::should_post_class_load()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
            Thread *thread = THREAD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
            assert(thread->is_Java_thread(), "thread->is_Java_thread()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
            JvmtiExport::post_class_load((JavaThread *) thread, k());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
      if (HAS_PENDING_EXCEPTION || k.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        // On error, clean up placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
        {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
          MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
          placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
          SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    Handle loader (THREAD, k->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
    oop kk = find_class_or_placeholder(name, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    assert(kk == k(), "should be present in dictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  // return if the protection domain in NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  if (protection_domain() == NULL) return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  // Check the protection domain has the right access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    // Note that we have an entry, and entries can be deleted only during GC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    // so we cannot allow GC to occur while we're holding this entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    // We're using a No_Safepoint_Verifier to catch any place where we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    // might potentially do a GC at all.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    // SystemDictionary::do_unloading() asserts that classes are only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    // unloaded at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    No_Safepoint_Verifier nosafepoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
                                                 class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
                                                 protection_domain)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
      return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  // Verify protection domain. If it fails an exception is thrown
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
  return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
// This routine does not lock the system dictionary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
// Since readers don't hold a lock, we must make sure that system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
// dictionary entries are only removed at a safepoint (when only one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
// thread is running), and are added to in a safe way (all links must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
// be updated in an MT-safe manner).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
// Callers should be aware that an entry could be added just after
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
// _dictionary->bucket(index) is read here, so the caller will not see
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
// the new entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
klassOop SystemDictionary::find(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
                                Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
                                Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
                                TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
2020
68d27ca96f33 6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents: 1550
diff changeset
   859
  // UseNewReflection
68d27ca96f33 6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents: 1550
diff changeset
   860
  // The result of this call should be consistent with the result
68d27ca96f33 6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents: 1550
diff changeset
   861
  // of the call to resolve_instance_class_or_null().
68d27ca96f33 6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents: 1550
diff changeset
   862
  // See evaluation 6790209 and 4474172 for more details.
68d27ca96f33 6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents: 1550
diff changeset
   863
  class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
68d27ca96f33 6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents: 1550
diff changeset
   864
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    // Note that we have an entry, and entries can be deleted only during GC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    // so we cannot allow GC to occur while we're holding this entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    // We're using a No_Safepoint_Verifier to catch any place where we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    // might potentially do a GC at all.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    // SystemDictionary::do_unloading() asserts that classes are only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    // unloaded at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    No_Safepoint_Verifier nosafepoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    return dictionary()->find(d_index, d_hash, class_name, class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
                              protection_domain, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
// Look for a loaded instance or array klass by name.  Do not do any loading.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
// return NULL in case of error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
                                                        Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
                                                        Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
                                                        TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  klassOop k = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  assert(class_name() != NULL, "class name must be non NULL");
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   890
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   891
  // Try to get one of the well-known klasses.
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   892
  if (LinkWellKnownClasses) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   893
    k = find_well_known_klass(class_name());
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   894
    if (k != NULL) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   895
      return k;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   896
    }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   897
  }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   898
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  if (FieldType::is_array(class_name())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    // The name refers to an array.  Parse the name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    jint dimension;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    symbolOop object_key;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    // dimension and object_key are assigned as a side-effect of this call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
    BasicType t = FieldType::get_array_info(class_name(), &dimension,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
                                            &object_key, CHECK_(NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
    if (t != T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
      k = Universe::typeArrayKlassObj(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      symbolHandle h_key(THREAD, object_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
      k = Klass::cast(k)->array_klass_or_null(dimension);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    k = find(class_name, class_loader, protection_domain, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   922
// Quick range check for names of well-known classes:
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   923
static symbolOop wk_klass_name_limits[2] = {NULL, NULL};
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   924
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   925
#ifndef PRODUCT
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   926
static int find_wkk_calls, find_wkk_probes, find_wkk_wins;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   927
// counts for "hello world": 3983, 1616, 1075
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   928
//  => 60% hit after limit guard, 25% total win rate
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   929
#endif
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   930
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   931
klassOop SystemDictionary::find_well_known_klass(symbolOop class_name) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   932
  // A bounds-check on class_name will quickly get a negative result.
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   933
  NOT_PRODUCT(find_wkk_calls++);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   934
  if (class_name >= wk_klass_name_limits[0] &&
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   935
      class_name <= wk_klass_name_limits[1]) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   936
    NOT_PRODUCT(find_wkk_probes++);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   937
    vmSymbols::SID sid = vmSymbols::find_sid(class_name);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   938
    if (sid != vmSymbols::NO_SID) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   939
      klassOop k = NULL;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   940
      switch (sid) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   941
        #define WK_KLASS_CASE(name, symbol, ignore_option) \
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   942
        case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   943
          k = WK_KLASS(name); break;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   944
        WK_KLASSES_DO(WK_KLASS_CASE)
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   945
        #undef WK_KLASS_CASE
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   946
      }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   947
      NOT_PRODUCT(if (k != NULL)  find_wkk_wins++);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   948
      return k;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   949
    }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   950
  }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   951
  return NULL;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   952
}
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
   953
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
// Note: this method is much like resolve_from_stream, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
// updates no supplemental data structures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
// TODO consolidate the two methods with a helper routine?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
klassOop SystemDictionary::parse_stream(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
                                        Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
                                        Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
                                        ClassFileStream* st,
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   961
                                        KlassHandle host_klass,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   962
                                        GrowableArray<Handle>* cp_patches,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
                                        TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  symbolHandle parsed_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  // Parse the stream. Note that we do this even though this klass might
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  // already be present in the SystemDictionary, otherwise we would not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  // throw potential ClassFormatErrors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  // Note: "name" is updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  // Further note:  a placeholder will be added for this class when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  //   super classes are loaded (resolve_super_or_fail). We expect this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  //   to be called for all classes but java.lang.Object; and we preload
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  //   java.lang.Object through resolve_or_fail, not this path.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
                                                             class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
                                                             protection_domain,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
   979
                                                             host_klass,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
   980
                                                             cp_patches,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
                                                             parsed_name,
3820
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 3575
diff changeset
   982
                                                             true,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
                                                             THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
   985
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  // We don't redefine the class, so we just need to clean up whether there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  // was an error or not (don't want to modify any system dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  // data structures).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  // Parsed name could be null if we threw an error before we got far
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  // enough along to parse it -- in that case, there is nothing to clean up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  if (!parsed_name.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    unsigned int p_hash = placeholders()->compute_hash(parsed_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
                                                       class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1002
  if (host_klass.not_null() && k.not_null()) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1003
    assert(AnonymousClasses, "");
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1004
    // If it's anonymous, initialize it now, since nobody else will.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1005
    k->set_host_klass(host_klass());
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1006
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1007
    {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1008
      MutexLocker mu_r(Compile_lock, THREAD);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1009
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1010
      // Add to class hierarchy, initialize vtables, and do possible
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1011
      // deoptimizations.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1012
      add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1013
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1014
      // But, do not add to system dictionary.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1015
    }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1016
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1017
    k->eager_initialize(THREAD);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1018
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1019
    // notify jvmti
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1020
    if (JvmtiExport::should_post_class_load()) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1021
        assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1022
        JvmtiExport::post_class_load((JavaThread *) THREAD, k());
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1023
    }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1024
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
  1025
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
// Add a klass to the system from a stream (called by jni_DefineClass and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
// JVM_DefineClass).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
// Note: class_name can be NULL. In that case we do not know the name of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
// the class until we have parsed the stream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
klassOop SystemDictionary::resolve_from_stream(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
                                               Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
                                               Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
                                               ClassFileStream* st,
3820
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 3575
diff changeset
  1038
                                               bool verify,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
                                               TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1041
  // Classloaders that support parallelism, e.g. bootstrap classloader,
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1042
  // or all classloaders with UnsyncloadClass do not acquire lock here
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1043
  bool DoObjectLock = true;
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1044
  if (is_parallelCapable(class_loader)) {
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1045
    DoObjectLock = false;
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1046
  }
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1047
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1048
  // Make sure we are synchronized on the class loader before we proceed
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
  Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  check_loader_lock_contention(lockObject, THREAD);
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1051
  ObjectLocker ol(lockObject, THREAD, DoObjectLock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  symbolHandle parsed_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  // Parse the stream. Note that we do this even though this klass might
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  // already be present in the SystemDictionary, otherwise we would not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  // throw potential ClassFormatErrors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  // Note: "name" is updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  // Further note:  a placeholder will be added for this class when
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  //   super classes are loaded (resolve_super_or_fail). We expect this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  //   to be called for all classes but java.lang.Object; and we preload
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  //   java.lang.Object through resolve_or_fail, not this path.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
                                                             class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
                                                             protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
                                                             parsed_name,
3820
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 3575
diff changeset
  1069
                                                             verify,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
                                                             THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  const char* pkg = "java/";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  if (!HAS_PENDING_EXCEPTION &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
      !class_loader.is_null() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
      !parsed_name.is_null() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
      !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    // It is illegal to define classes in the "java." package from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    char* name = parsed_name->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    char* index = strrchr(name, '/');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    *index = '\0'; // chop to just the package name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    while ((index = strchr(name, '/')) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
      *index = '.'; // replace '/' with '.' in package name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    const char* fmt = "Prohibited package name: %s";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
    size_t len = strlen(fmt) + strlen(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
    char* message = NEW_RESOURCE_ARRAY(char, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
    jio_snprintf(message, len, fmt, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    Exceptions::_throw_msg(THREAD_AND_LOCATION,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
      vmSymbols::java_lang_SecurityException(), message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  if (!HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
    assert(!parsed_name.is_null(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
    assert(class_name.is_null() || class_name() == parsed_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
           "name mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
    // Verification prevents us from creating names with dots in them, this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
    // asserts that that's the case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
    assert(is_internal_format(parsed_name),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
           "external class name format used internally");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    // Add class just loaded
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1104
    // If a class loader supports parallel classloading handle parallel define requests
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1105
    // find_or_define_instance_class may return a different instanceKlass
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1106
    if (is_parallelCapable(class_loader)) {
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1107
      k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1108
    } else {
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1109
      define_instance_class(k, THREAD);
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1110
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  // If parsing the class file or define_instance_class failed, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  // need to remove the placeholder added on our behalf. But we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  // must make sure parsed_name is valid first (it won't be if we had
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  // a format error before the class was parsed far enough to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  // find the name).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
  if (HAS_PENDING_EXCEPTION && !parsed_name.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
    unsigned int p_hash = placeholders()->compute_hash(parsed_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
                                                       class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
    int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
    placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
    SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  // Make sure that we didn't leave a place holder in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  // SystemDictionary; this is only done on success
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  debug_only( {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    if (!HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      assert(!parsed_name.is_null(), "parsed_name is still null?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
      symbolHandle h_name   (THREAD, k->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
      Handle h_loader (THREAD, k->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
      MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
      oop check = find_class_or_placeholder(parsed_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
      assert(check == k(), "should be present in the dictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      oop check2 = find_class_or_placeholder(h_name, h_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
      assert(check == check2, "name inconsistancy in SystemDictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  } );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
void SystemDictionary::set_shared_dictionary(HashtableBucket* t, int length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
                                             int number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
  assert(length == _nof_buckets * sizeof(HashtableBucket),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
         "bad shared dictionary size.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
// If there is a shared dictionary, then find the entry for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
// given shared system class, if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
klassOop SystemDictionary::find_shared_class(symbolHandle class_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  if (shared_dictionary() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    unsigned int d_hash = dictionary()->compute_hash(class_name, Handle());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
// Load a class from the shared spaces (found through the shared system
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
// dictionary).  Force the superclass and all interfaces to be loaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
// Update the class definition to include sibling classes and no
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
// subclasses (yet).  [Classes in the shared space are not part of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
// object hierarchy until loaded.]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
instanceKlassHandle SystemDictionary::load_shared_class(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
                 symbolHandle class_name, Handle class_loader, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  instanceKlassHandle ik (THREAD, find_shared_class(class_name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  return load_shared_class(ik, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
// Note well!  Changes to this method may affect oop access order
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
// in the shared archive.  Please take care to not make changes that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
// adversely affect cold start time by changing the oop access order
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
// that is specified in dump.cpp MarkAndMoveOrderedReadOnly and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
// MarkAndMoveOrderedReadWrite closures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
instanceKlassHandle SystemDictionary::load_shared_class(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
                 instanceKlassHandle ik, Handle class_loader, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  assert(class_loader.is_null(), "non-null classloader for shared class?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  if (ik.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    instanceKlassHandle nh = instanceKlassHandle(); // null Handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    symbolHandle class_name(THREAD, ik->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    // Found the class, now load the superclass and interfaces.  If they
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    // are shared, add them to the main system dictionary and reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    // their hierarchy references (supers, subs, and interfaces).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
    if (ik->super() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
      symbolHandle cn(THREAD, ik->super()->klass_part()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
      resolve_super_or_fail(class_name, cn,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
                            class_loader, Handle(), true, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    objArrayHandle interfaces (THREAD, ik->local_interfaces());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    int num_interfaces = interfaces->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
    for (int index = 0; index < num_interfaces; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
      klassOop k = klassOop(interfaces->obj_at(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
      // Note: can not use instanceKlass::cast here because
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
      // interfaces' instanceKlass's C++ vtbls haven't been
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
      // reinitialized yet (they will be once the interface classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
      // are loaded)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
      symbolHandle name (THREAD, k->klass_part()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
      resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    // Adjust methods to recover missing data.  They need addresses for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    // interpreter entry points and their default native method address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    // must be reset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    // Updating methods must be done under a lock so multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
    // threads don't update these in parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    // Shared classes are all currently loaded by the bootstrap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    // classloader, so this will never cause a deadlock on
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    // a custom class loader lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
      Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
      check_loader_lock_contention(lockObject, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
      ObjectLocker ol(lockObject, THREAD, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
      objArrayHandle methods (THREAD, ik->methods());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
      int num_methods = methods->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
      for (int index2 = 0; index2 < num_methods; ++index2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
        methodHandle m(THREAD, methodOop(methods->obj_at(index2)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
        m()->link_method(m, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    if (TraceClassLoading) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
      tty->print("[Loaded %s", ik->external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
      tty->print(" from shared objects file");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
      tty->print_cr("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
    // notify a class loaded from shared object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
                                             true /* shared class */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
  return ik;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
#ifdef KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
// Some classes on the bootstrap class path haven't been installed on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
// system yet.  Call the DownloadManager method to make them appear in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
// bootstrap class path and try again to load the named class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
// Note that with delegation class loaders all classes in another loader will
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
// first try to call this so it'd better be fast!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
static instanceKlassHandle download_and_retry_class_load(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
                                                    symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
                                                    TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  instanceKlassHandle nk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
  // If download manager class isn't loaded just return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  if (dlm == NULL) return nk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  { HandleMark hm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nk));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    Handle class_string = java_lang_String::externalize_classname(s, CHECK_(nk));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
    // return value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
    JavaValue result(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
    // Call the DownloadManager.  We assume that it has a lock because
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
    // multiple classes could be not found and downloaded at the same time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
    // class sun.misc.DownloadManager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
    // public static String getBootClassPathEntryForClass(String className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
    JavaCalls::call_static(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
                       KlassHandle(THREAD, dlm),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
                       vmSymbolHandles::getBootClassPathEntryForClass_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
                       vmSymbolHandles::string_string_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
                       class_string,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
                       CHECK_(nk));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    // Get result.string and add to bootclasspath
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    assert(result.get_type() == T_OBJECT, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    oop obj = (oop) result.get_jobject();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
    if (obj == NULL) { return nk; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
195
9193828514c4 6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents: 1
diff changeset
  1297
    Handle h_obj(THREAD, obj);
9193828514c4 6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents: 1
diff changeset
  1298
    char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj,
9193828514c4 6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents: 1
diff changeset
  1299
                                                                  CHECK_(nk));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    // lock the loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
    // we use this lock because JVMTI does.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
    Handle loader_lock(THREAD, SystemDictionary::system_loader_lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    ObjectLocker ol(loader_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    // add the file to the bootclasspath
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
    ClassLoader::update_class_path_entry_list(new_class_name, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  } // end HandleMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
  if (TraceClassLoading) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
    ClassLoader::print_bootclasspath();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  return ClassLoader::load_classfile(class_name, CHECK_(nk));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
#endif // KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
instanceKlassHandle SystemDictionary::load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
  if (class_loader.is_null()) {
3575
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1321
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    // Search the shared system dictionary for classes preloaded into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    // shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
    instanceKlassHandle k;
3575
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1325
    {
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1326
      PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1327
      k = load_shared_class(class_name, class_loader, THREAD);
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1328
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    if (k.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
      // Use VM class loader
3575
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1332
      PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
      k = ClassLoader::load_classfile(class_name, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
#ifdef KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
    // If the VM class loader has failed to load the class, call the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    // DownloadManager class to make it magically appear on the classpath
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
    // and try again.  This is only configured with the Kernel VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
    if (k.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
      k = download_and_retry_class_load(class_name, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
#endif // KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1345
    // find_or_define_instance_class may return a different instanceKlass
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    if (!k.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
      k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
    // Use user specified class loader to load class. Call loadClass operation on class_loader.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
3575
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1354
    assert(THREAD->is_Java_thread(), "must be a JavaThread");
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1355
    JavaThread* jt = (JavaThread*) THREAD;
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1356
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1357
    PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1358
                               ClassLoader::perf_app_classload_selftime(),
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1359
                               ClassLoader::perf_app_classload_count(),
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1360
                               jt->get_thread_stat()->perf_recursion_counts_addr(),
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1361
                               jt->get_thread_stat()->perf_timers_addr(),
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1362
                               PerfClassTraceTime::CLASS_LOAD);
224791e7ecab 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 2570
diff changeset
  1363
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
    Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
    // Translate to external class name format, i.e., convert '/' chars to '.'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    Handle string = java_lang_String::externalize_classname(s, CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    JavaValue result(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
    KlassHandle spec_klass (THREAD, SystemDictionary::classloader_klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1372
    // Call public unsynchronized loadClass(String) directly for all class loaders
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1373
    // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1374
    // acquire a class-name based lock rather than the class loader object lock.
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1375
    // JDK < 7 already acquire the class loader lock in loadClass(String, boolean),
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1376
    // so the call to loadClassInternal() was not required.
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1377
    //
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1378
    // UnsyncloadClass flag means both call loadClass(String) and do
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1379
    // not acquire the class loader lock even for class loaders that are
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1380
    // not parallelCapable. This was a risky transitional
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1381
    // flag for diagnostic purposes only. It is risky to call
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
    // custom class loaders without synchronization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    // WARNING If a custom class loader does NOT synchronizer findClass, or callers of
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1384
    // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
    // Do NOT assume this will be supported in future releases.
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1386
    //
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1387
    // Added MustCallLoadClassInternal in case we discover in the field
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1388
    // a customer that counts on this call
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1389
    if (MustCallLoadClassInternal && has_loadClassInternal()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
      JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
                              class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
                              spec_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
                              vmSymbolHandles::loadClassInternal_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
                              vmSymbolHandles::string_class_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
                              string,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
                              CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      JavaCalls::call_virtual(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
                              class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
                              spec_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
                              vmSymbolHandles::loadClass_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
                              vmSymbolHandles::string_class_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
                              string,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
                              CHECK_(nh));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    assert(result.get_type() == T_OBJECT, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
    oop obj = (oop) result.get_jobject();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
    // Primitive classes return null since forName() can not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
    // used to obtain any of the Class objects representing primitives or void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
    if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
      instanceKlassHandle k =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
                instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
      // For user defined Java class loaders, check that the name returned is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
      // the same as that requested.  This check is done for the bootstrap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
      // loader when parsing the class file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
      if (class_name() == k->name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
        return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
    // Class is not found or has the wrong name, return NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
    return nh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  Handle class_loader_h(THREAD, k->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1431
 // for bootstrap and other parallel classloaders don't acquire lock,
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1432
 // use placeholder token
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1433
 // If a parallelCapable class loader calls define_instance_class instead of
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1434
 // find_or_define_instance_class to get here, we have a timing
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1435
 // hole with systemDictionary updates and check_constraints
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1436
 if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
         compute_loader_lock_object(class_loader_h, THREAD)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
         "define called without lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
  // Check class-loading constraints. Throw exception if violation is detected.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
  // Grabs and releases SystemDictionary_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
  // The check_constraints/find_class call and update_dictionary sequence
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
  // must be "atomic" for a specific class/classloader pair so we never
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
  // define two different instanceKlasses for that class/classloader pair.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
  // Existing classloaders will call define_instance_class with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
  // classloader lock held
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
  // Parallel classloaders will call find_or_define_instance_class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
  // which will require a token to perform the define class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  symbolHandle name_h(THREAD, k->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
  // Register class just loaded with class loader (placed in Vector)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
  // Note we do this before updating the dictionary, as this can
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  // fail with an OutOfMemoryError (if it does, we will *not* put this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
  // class in the dictionary and will not update the class hierarchy).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
  if (k->class_loader() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    methodHandle m(THREAD, Universe::loader_addClass_method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
    JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
    JavaCallArguments args(class_loader_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
    args.push_oop(Handle(THREAD, k->java_mirror()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
    JavaCalls::call(&result, m, &args, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
  // Add the new class. We need recompile lock during update of CHA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
    unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
    int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
    MutexLocker mu_r(Compile_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
    // Add to class hierarchy, initialize vtables, and do possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
    // deoptimizations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
    add_to_hierarchy(k, CHECK); // No exception, but can block
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
    // Add to systemDictionary - so other classes can see it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
    // Grabs and releases SystemDictionary_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    update_dictionary(d_index, d_hash, p_index, p_hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
                      k, class_loader_h, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
  k->eager_initialize(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  // notify jvmti
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
  if (JvmtiExport::should_post_class_load()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
      assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
      JvmtiExport::post_class_load((JavaThread *) THREAD, k());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
// Support parallel classloading
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1495
// All parallel class loaders, including bootstrap classloader
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1496
// lock a placeholder entry for this class/class_loader pair
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1497
// to allow parallel defines of different classes for this class loader
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1498
// With AllowParallelDefine flag==true, in case they do not synchronize around
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1499
// FindLoadedClass/DefineClass, calls, we check for parallel
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
// loading for them, wait if a defineClass is in progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
// and return the initial requestor's results
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1502
// This flag does not apply to the bootstrap classloader.
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1503
// With AllowParallelDefine flag==false, call through to define_instance_class
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1504
// which will throw LinkageError: duplicate class definition.
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1505
// False is the requested default.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
// For better performance, the class loaders should synchronize
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1507
// findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
// potentially waste time reading and parsing the bytestream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
// Note: VM callers should ensure consistency of k/class_name,class_loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
  instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1513
  symbolHandle name_h(THREAD, k->name()); // passed in class_name may be null
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1515
  unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
// Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1519
  unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
  int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
  PlaceholderEntry* probe;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
    // First check if class already defined
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1526
    if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1527
      klassOop check = find_class(d_index, d_hash, name_h, class_loader);
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1528
      if (check != NULL) {
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1529
        return(instanceKlassHandle(THREAD, check));
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1530
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    // Acquire define token for this class/classloader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
    symbolHandle nullsymbolHandle;
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1535
    probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD);
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1536
    // Wait if another thread defining in parallel
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1537
    // All threads wait - even those that will throw duplicate class: otherwise
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1538
    // caller is surprised by LinkageError: duplicate, but findLoadedClass fails
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1539
    // if other thread has not finished updating dictionary
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1540
    while (probe->definer() != NULL) {
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1541
      SystemDictionary_lock->wait();
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1542
    }
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1543
    // Only special cases allow parallel defines and can use other thread's results
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1544
    // Other cases fall through, and may run into duplicate defines
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1545
    // caught by finding an entry in the SystemDictionary
4445
1356c4b003de 6893504: LinkageError for bootstrap duplicate class definitions.
acorn
parents: 4094
diff changeset
  1546
    if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
        probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1548
        placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1549
        SystemDictionary_lock->notify_all();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
#ifdef ASSERT
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1551
        klassOop check = find_class(d_index, d_hash, name_h, class_loader);
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1552
        assert(check != NULL, "definer missed recording success");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
#endif
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1554
        return(instanceKlassHandle(THREAD, probe->instanceKlass()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
    } else {
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1556
      // This thread will define the class (even if earlier thread tried and had an error)
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  1557
      probe->set_definer(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
  define_instance_class(k, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
  Handle linkage_exception = Handle(); // null handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
  // definer must notify any waiting threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
    MutexLocker mu(SystemDictionary_lock, THREAD);
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1568
    PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
    assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
    if (probe != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
      if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
        linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
        CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
        probe->set_instanceKlass(k());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
      probe->set_definer(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
      probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
1891
33f8185f669e 6791656: nsk defclass0 asserts handles.hpp
acorn
parents: 1890
diff changeset
  1579
      placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
      SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
  // Can't throw exception while holding lock due to rank ordering
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  if (linkage_exception() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
    THROW_OOP_(linkage_exception(), nh); // throws exception and returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
  // If class_loader is NULL we synchronize on _system_loader_lock_obj
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  if (class_loader.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
    return Handle(THREAD, _system_loader_lock_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
    return class_loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
// This method is added to check how often we have to wait to grab loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
// lock. The results are being recorded in the performance counters defined in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
// ClassLoader::_sync_systemLoaderLockContentionRate and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
// ClassLoader::_sync_nonSystemLoaderLockConteionRate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  if (!UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  assert(!loader_lock.is_null(), "NULL lock object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
  if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
      == ObjectSynchronizer::owner_other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    // contention will likely happen, so increment the corresponding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    // contention counter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    if (loader_lock() == _system_loader_lock_obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
      ClassLoader::sync_systemLoaderLockContentionRate()->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
      ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
// Lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
klassOop SystemDictionary::find_class(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
                                      symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
                                      Handle class_loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
  assert (index == dictionary()->index_for(class_name, class_loader),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
          "incorrect index?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
  klassOop k = dictionary()->find_class(index, hash, class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
  return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
// Basic find on classes in the midst of being loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
symbolOop SystemDictionary::find_placeholder(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
                                             symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
                                             Handle class_loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
  return placeholders()->find_entry(index, hash, class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
// Used for assertions and verification only
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
oop SystemDictionary::find_class_or_placeholder(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
                                                Handle class_loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  #ifndef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  guarantee(VerifyBeforeGC   ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
            VerifyDuringGC   ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
            VerifyBeforeExit ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
            VerifyAfterGC, "too expensive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
  symbolOop class_name_ = class_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
  oop class_loader_ = class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  // First look in the loaded class array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
  int d_index = dictionary()->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  oop lookup = find_class(d_index, d_hash, class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  if (lookup == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
    // Next try the placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
    unsigned int p_hash = placeholders()->compute_hash(class_name,class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    lookup = find_placeholder(p_index, p_hash, class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
  return lookup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
// Get the next class in the diictionary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
klassOop SystemDictionary::try_get_next_class() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
  return dictionary()->try_get_next_class();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
// Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
// is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
// before a new class is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
  assert(k.not_null(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
  // Link into hierachy. Make sure the vtables are initialized before linking into
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  k->append_to_sibling_list();                    // add to superklass/sibling list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  k->process_interfaces(THREAD);                  // handle all "implements" declarations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
  k->set_init_state(instanceKlass::loaded);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
  // Now flush all code that depended on old class hierarchy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
  // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
  // Also, first reinitialize vtable because it may have gotten out of synch
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
  // while the new class wasn't connected to the class hierarchy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  Universe::flush_dependents_on(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
// GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
// Following roots during mark-sweep is separated in two phases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
// The first phase follows preloaded classes and all other system
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
// classes, since these will never get unloaded anyway.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
// The second phase removes (unloads) unreachable classes from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
// system dictionary and follows the remaining classes' contents.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
  // Follow preloaded classes/mirrors and system loader object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
  blk->do_oop(&_java_system_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
  preloaded_oops_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
  always_strong_classes_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
void SystemDictionary::always_strong_classes_do(OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
  // Follow all system classes and temporary placeholders in dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  dictionary()->always_strong_classes_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
  // Placeholders. These are *always* strong roots, as they
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  // represent classes we're actively loading.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  placeholders_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1729
  // Visit extra methods
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1730
  if (invoke_method_table() != NULL)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1731
    invoke_method_table()->oops_do(blk);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1732
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  // Loader constraints. We must keep the symbolOop used in the name alive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
  constraints()->always_strong_classes_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
  // Resolution errors keep the symbolOop for the error alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
  resolution_errors()->always_strong_classes_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
void SystemDictionary::placeholders_do(OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  placeholders()->oops_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
  bool result = dictionary()->do_unloading(is_alive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  constraints()->purge_loader_constraints(is_alive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  resolution_errors()->purge_resolution_errors(is_alive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
// The mirrors are scanned by shared_oops_do() which is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
// not called by oops_do().  In order to process oops in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
// a necessary order, shared_oops_do() is call by
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
// Universe::oops_do().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
void SystemDictionary::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
  // Adjust preloaded classes and system loader object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  f->do_oop(&_java_system_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
  preloaded_oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
  lazily_loaded_oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  // Adjust dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
  dictionary()->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1768
  // Visit extra methods
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1769
  if (invoke_method_table() != NULL)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1770
    invoke_method_table()->oops_do(f);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1771
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  // Partially loaded classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
  placeholders()->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  // Adjust constraint table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  constraints()->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  // Adjust resolution error table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  resolution_errors()->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
void SystemDictionary::preloaded_oops_do(OopClosure* f) {
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1784
  f->do_oop((oop*) &wk_klass_name_limits[0]);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1785
  f->do_oop((oop*) &wk_klass_name_limits[1]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1787
  for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1788
    f->do_oop((oop*) &_well_known_klasses[k]);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1789
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    for (int i = 0; i < T_VOID+1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
      if (_box_klasses[i] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
        assert(i >= T_BOOLEAN, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
        f->do_oop((oop*) &_box_klasses[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  // The basic type mirrors would have already been processed in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
  // Universe::oops_do(), via a call to shared_oops_do(), so should
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
  // not be processed again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
  f->do_oop((oop*) &_system_loader_lock_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
  FilteredFieldsMap::klasses_oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  f->do_oop((oop*) &_abstract_ownable_synchronizer_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
// Just the classes from defining class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
// Don't iterate over placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
void SystemDictionary::classes_do(void f(klassOop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
  dictionary()->classes_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
// Added for initialize_itable_for_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
//   Just the classes from defining class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
// Don't iterate over placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
  dictionary()->classes_do(f, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
//   All classes, and their class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
// Don't iterate over placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
void SystemDictionary::classes_do(void f(klassOop, oop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
  dictionary()->classes_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
//   All classes, and their class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
//   (added for helpers that use HandleMarks and ResourceMarks)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
// Don't iterate over placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
  dictionary()->classes_do(f, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
void SystemDictionary::placeholders_do(void f(symbolOop, oop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
  placeholders()->entries_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
void SystemDictionary::methods_do(void f(methodOop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
  dictionary()->methods_do(f);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1844
  if (invoke_method_table() != NULL)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1845
    invoke_method_table()->methods_do(f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
// Lazily load klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
  assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
  // if multiple threads calling this function, only one thread will load
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
  // the class.  The other threads will find the loaded version once the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
  // class is loaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
  klassOop aos = _abstract_ownable_synchronizer_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
  if (aos == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
    klassOop k = resolve_or_fail(vmSymbolHandles::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
    // Force a fence to prevent any read before the write completes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
    OrderAccess::fence();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
    _abstract_ownable_synchronizer_klass = k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
// Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
void SystemDictionary::initialize(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
  // Allocate arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
  assert(dictionary() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
         "SystemDictionary should only be initialized once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
  _dictionary = new Dictionary(_nof_buckets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  _placeholders = new PlaceholderTable(_nof_buckets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  _number_of_modifications = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
  _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1878
  // _invoke_method_table is allocated lazily in find_method_handle_invoke()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
  // Allocate private object used as system class loader lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
  _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
  // Initialize basic classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
  initialize_preloaded_classes(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1886
// Compact table of directions on the initialization of klasses:
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1887
static const short wk_init_info[] = {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1888
  #define WK_KLASS_INIT_INFO(name, symbol, option) \
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1889
    ( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1890
          << SystemDictionary::CEIL_LG_OPTION_LIMIT) \
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1891
      | (int)SystemDictionary::option ),
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1892
  WK_KLASSES_DO(WK_KLASS_INIT_INFO)
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1893
  #undef WK_KLASS_INIT_INFO
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1894
  0
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1895
};
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1896
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1897
bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1898
  assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1899
  int  info = wk_init_info[id - FIRST_WKID];
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1900
  int  sid  = (info >> CEIL_LG_OPTION_LIMIT);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1901
  symbolHandle symbol = vmSymbolHandles::symbol_handle_at((vmSymbols::SID)sid);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1902
  klassOop*    klassp = &_well_known_klasses[id];
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1903
  bool must_load = (init_opt < SystemDictionary::Opt);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1904
  bool try_load  = true;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1905
  if (init_opt == SystemDictionary::Opt_Kernel) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1906
#ifndef KERNEL
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1907
    try_load = false;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1908
#endif //KERNEL
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1909
  }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1910
  if ((*klassp) == NULL && try_load) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1911
    if (must_load) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1912
      (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1913
    } else {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1914
      (*klassp) = resolve_or_null(symbol,       CHECK_0); // load optional klass
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1915
    }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1916
  }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1917
  return ((*klassp) != NULL);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1918
}
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1919
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1920
void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1921
  assert((int)start_id <= (int)limit_id, "IDs are out of order!");
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1922
  for (int id = (int)start_id; id < (int)limit_id; id++) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1923
    assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1924
    int info = wk_init_info[id - FIRST_WKID];
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1925
    int sid  = (info >> CEIL_LG_OPTION_LIMIT);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1926
    int opt  = (info & right_n_bits(CEIL_LG_OPTION_LIMIT));
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1927
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1928
    initialize_wk_klass((WKID)id, opt, CHECK);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1929
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1930
    // Update limits, so find_well_known_klass can be very fast:
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1931
    symbolOop s = vmSymbols::symbol_at((vmSymbols::SID)sid);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1932
    if (wk_klass_name_limits[1] == NULL) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1933
      wk_klass_name_limits[0] = wk_klass_name_limits[1] = s;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1934
    } else if (wk_klass_name_limits[1] < s) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1935
      wk_klass_name_limits[1] = s;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1936
    } else if (wk_klass_name_limits[0] > s) {
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1937
      wk_klass_name_limits[0] = s;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1938
    }
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1939
  }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1940
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1941
  // move the starting value forward to the limit:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1942
  start_id = limit_id;
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1943
}
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1944
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
void SystemDictionary::initialize_preloaded_classes(TRAPS) {
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1947
  assert(WK_KLASS(object_klass) == NULL, "preloaded classes should only be initialized once");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
  // Preload commonly used klasses
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1949
  WKID scan = FIRST_WKID;
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1950
  // first do Object, String, Class
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1951
  initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(class_klass), scan, CHECK);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1952
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1953
  debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(class_klass)));
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1954
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
  // Fixup mirrors for classes loaded before java.lang.Class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
  // These calls iterate over the objects currently in the perm gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
  // so calling them at this point is matters (not before when there
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
  // are fewer objects and not later after there are more objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
  // in the perm gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
  Universe::initialize_basic_type_mirrors(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
  Universe::fixup_mirrors(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1963
  // do a bunch more:
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1964
  initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(reference_klass), scan, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
  // Preload ref klasses and set reference types
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1967
  instanceKlass::cast(WK_KLASS(reference_klass))->set_reference_type(REF_OTHER);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1968
  instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(reference_klass));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1970
  initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(phantom_reference_klass), scan, CHECK);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1971
  instanceKlass::cast(WK_KLASS(soft_reference_klass))->set_reference_type(REF_SOFT);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1972
  instanceKlass::cast(WK_KLASS(weak_reference_klass))->set_reference_type(REF_WEAK);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1973
  instanceKlass::cast(WK_KLASS(final_reference_klass))->set_reference_type(REF_FINAL);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1974
  instanceKlass::cast(WK_KLASS(phantom_reference_klass))->set_reference_type(REF_PHANTOM);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1975
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1976
  WKID meth_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1977
  WKID meth_group_end   = WK_KLASS_ENUM_NAME(WrongMethodTypeException_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1978
  initialize_wk_klasses_until(meth_group_start, scan, CHECK);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1979
  if (EnableMethodHandles) {
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3912
diff changeset
  1980
    initialize_wk_klasses_through(meth_group_end, scan, CHECK);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1981
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1982
  if (_well_known_klasses[meth_group_start] == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1983
    // Skip the rest of the method handle classes, if MethodHandle is not loaded.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1984
    scan = WKID(meth_group_end+1);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1985
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1986
  WKID indy_group_start = WK_KLASS_ENUM_NAME(Linkage_klass);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4446
diff changeset
  1987
  WKID indy_group_end   = WK_KLASS_ENUM_NAME(InvokeDynamic_klass);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1988
  initialize_wk_klasses_until(indy_group_start, scan, CHECK);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1989
  if (EnableInvokeDynamic) {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  1990
    initialize_wk_klasses_through(indy_group_end, scan, CHECK);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1991
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1992
  if (_well_known_klasses[indy_group_start] == NULL) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1993
    // Skip the rest of the dynamic typing classes, if Linkage is not loaded.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1994
    scan = WKID(indy_group_end+1);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1995
  }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  1996
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1997
  initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  1999
  _box_klasses[T_BOOLEAN] = WK_KLASS(boolean_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2000
  _box_klasses[T_CHAR]    = WK_KLASS(char_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2001
  _box_klasses[T_FLOAT]   = WK_KLASS(float_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2002
  _box_klasses[T_DOUBLE]  = WK_KLASS(double_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2003
  _box_klasses[T_BYTE]    = WK_KLASS(byte_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2004
  _box_klasses[T_SHORT]   = WK_KLASS(short_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2005
  _box_klasses[T_INT]     = WK_KLASS(int_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2006
  _box_klasses[T_LONG]    = WK_KLASS(long_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2007
  //_box_klasses[T_OBJECT]  = WK_KLASS(object_klass);
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2008
  //_box_klasses[T_ARRAY]   = WK_KLASS(object_klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
#ifdef KERNEL
379
10767ca40189 6652736: well known classes in system dictionary are inefficiently processed
jrose
parents: 195
diff changeset
  2011
  if (sun_jkernel_DownloadManager_klass() == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
    warning("Cannot find sun/jkernel/DownloadManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
#endif // KERNEL
1890
9ce941df84eb 4670071: loadClassInternal is too restrictive.
acorn
parents: 1550
diff changeset
  2015
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
  { // Compute whether we should use loadClass or loadClassInternal when loading classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
    methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
    _has_loadClassInternal = (method != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
  { // Compute whether we should use checkPackageAccess or NOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
    methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
    _has_checkPackageAccess = (method != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
// Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
// If so, returns the basic type it holds.  If not, returns T_OBJECT.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
BasicType SystemDictionary::box_klass_type(klassOop k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
  assert(k != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
  for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
    if (_box_klasses[i] == k)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
      return (BasicType)i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
  return T_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2037
KlassHandle SystemDictionaryHandles::box_klass(BasicType t) {
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2038
  if (t >= T_BOOLEAN && t <= T_VOID)
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2039
    return KlassHandle(&SystemDictionary::_box_klasses[t], true);
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2040
  else
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2041
    return KlassHandle();
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2042
}
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2043
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
// Constraints on class loaders. The details of the algorithm can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
// found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
// Virtual Machine" by Sheng Liang and Gilad Bracha.  The basic idea is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
// that the system dictionary needs to maintain a set of contraints that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
// must be satisfied by all classes in the dictionary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
// if defining is true, then LinkageError if already in systemDictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
// if initiating loader, then ok if instanceKlass matches existing entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
                                         instanceKlassHandle k,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
                                         Handle class_loader, bool defining,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
                                         TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
  const char *linkage_error = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
    symbolHandle name (THREAD, k->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
    klassOop check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
    if (check != (klassOop)NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
      // if different instanceKlass - duplicate class definition,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
      // else - ok, class loaded by a different thread in parallel,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
      // we should only have found it if it was done loading and ok to use
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
      // system dictionary only holds instance classes, placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
      // also holds array classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
      assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
      if ((defining == true) || (k() != check)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
        linkage_error = "loader (instance of  %s): attempted  duplicate class "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
          "definition for name: \"%s\"";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
    unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
    int p_index = placeholders()->hash_to_index(p_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
    symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
    assert(ph_check == NULL || ph_check == name(), "invalid symbol");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
    if (linkage_error == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
      if (constraints()->check_or_update(k, class_loader, name) == false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
        linkage_error = "loader constraint violation: loader (instance of %s)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
          " previously initiated loading for a different type with name \"%s\"";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
  // Throw error now if needed (cannot throw while holding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
  // SystemDictionary_lock because of rank ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
  if (linkage_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
    const char* class_loader_name = loader_name(class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
    char* type_name = k->name()->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
    size_t buflen = strlen(linkage_error) + strlen(class_loader_name) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
      strlen(type_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
    char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
    jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
    THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
// Update system dictionary - done after check_constraint and add_to_hierachy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
// have been called.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
                                         int p_index, unsigned int p_hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
                                         instanceKlassHandle k,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
                                         Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
                                         TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
  // Compile_lock prevents systemDictionary updates during compilations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
  assert_locked_or_safepoint(Compile_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
  symbolHandle name (THREAD, k->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
  MutexLocker mu1(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
  // See whether biased locking is enabled and if so set it for this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
  // klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
  // Note that this must be done past the last potential blocking
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
  // point / safepoint. We enable biased locking lazily using a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
  // VM_Operation to iterate the SystemDictionary and installing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
  // biasable mark word into each instanceKlass's prototype header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
  // To avoid race conditions where we accidentally miss enabling the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
  // optimization for one class in the process of being added to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
  // dictionary, we must not safepoint after the test of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
  // BiasedLocking::enabled().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
  if (UseBiasedLocking && BiasedLocking::enabled()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
    // Set biased locking bit for all loaded classes; it will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
    // cleared if revocation occurs too often for this type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
    // NOTE that we must only do this when the class is initally
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
    // defined, not each time it is referenced from a new class loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
    if (k->class_loader() == class_loader()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
      k->set_prototype_header(markOopDesc::biased_locking_prototype());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
  // Check for a placeholder. If there, remove it and make a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
  // new system dictionary entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
  placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
  klassOop sd_check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
  if (sd_check == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
    dictionary()->add_klass(name, class_loader, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
    notice_modification();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
  sd_check = find_class(d_index, d_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
  assert (sd_check != NULL, "should have entry in system dictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
// Changed to allow PH to remain to complete class circularity checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
// while only one thread can define a class at one time, multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
// classes can resolve the superclass for a class at one time,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
// and the placeholder is used to track that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
//  symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
//  assert (ph_check == NULL, "should not have a placeholder entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
    SystemDictionary_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
klassOop SystemDictionary::find_constrained_instance_or_array_klass(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
                    symbolHandle class_name, Handle class_loader, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
  // First see if it has been loaded directly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
  // Force the protection domain to be null.  (This removes protection checks.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
  Handle no_protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
  klassOop klass = find_instance_or_array_klass(class_name, class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
                                                no_protection_domain, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
  if (klass != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
    return klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
  // Now look to see if it has been loaded elsewhere, and is subject to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
  // a loader constraint that would require this loader to return the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
  // klass that is already loaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
  if (FieldType::is_array(class_name())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
    // Array classes are hard because their klassOops are not kept in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
    // constraint table. The array klass may be constrained, but the elem class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
    // may not be.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
    jint dimension;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
    symbolOop object_key;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
    BasicType t = FieldType::get_array_info(class_name(), &dimension,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
                                            &object_key, CHECK_(NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
    if (t != T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
      klass = Universe::typeArrayKlassObj(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
      symbolHandle elem_name(THREAD, object_key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
      MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
      klass = constraints()->find_constrained_elem_klass(class_name, elem_name, class_loader, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
    if (klass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
      klass = Klass::cast(klass)->array_klass_or_null(dimension);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
    MutexLocker mu(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
    // Non-array classes are easy: simply check the constraint table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
    klass = constraints()->find_constrained_klass(class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
  return klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
bool SystemDictionary::add_loader_constraint(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
                                             Handle class_loader1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
                                             Handle class_loader2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
                                             Thread* THREAD) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
  unsigned int d_hash1 = dictionary()->compute_hash(class_name, class_loader1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
  int d_index1 = dictionary()->hash_to_index(d_hash1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
  unsigned int d_hash2 = dictionary()->compute_hash(class_name, class_loader2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
  int d_index2 = dictionary()->hash_to_index(d_hash2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
    MutexLocker mu_s(SystemDictionary_lock, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
    // Better never do a GC while we're holding these oops
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
    No_Safepoint_Verifier nosafepoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
    klassOop klass1 = find_class(d_index1, d_hash1, class_name, class_loader1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
    klassOop klass2 = find_class(d_index2, d_hash2, class_name, class_loader2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
    return constraints()->add_entry(class_name, klass1, class_loader1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
                                    klass2, class_loader2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
// Add entry to resolution error table to record the error when the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
// attempt to resolve a reference to a class has failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, symbolHandle error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
  unsigned int hash = resolution_errors()->compute_hash(pool, which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
  int index = resolution_errors()->hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
    MutexLocker ml(SystemDictionary_lock, Thread::current());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
    resolution_errors()->add_entry(index, hash, pool, which, error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
// Lookup resolution error table. Returns error if found, otherwise NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
symbolOop SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
  unsigned int hash = resolution_errors()->compute_hash(pool, which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
  int index = resolution_errors()->hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
    MutexLocker ml(SystemDictionary_lock, Thread::current());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
    ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
    return (entry != NULL) ? entry->error() : (symbolOop)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2254
// Signature constraints ensure that callers and callees agree about
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2255
// the meaning of type names in their signatures.  This routine is the
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2256
// intake for constraints.  It collects them from several places:
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2257
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2258
//  * LinkResolver::resolve_method (if check_access is true) requires
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2259
//    that the resolving class (the caller) and the defining class of
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2260
//    the resolved method (the callee) agree on each type in the
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2261
//    method's signature.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2262
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2263
//  * LinkResolver::resolve_interface_method performs exactly the same
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2264
//    checks.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2265
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2266
//  * LinkResolver::resolve_field requires that the constant pool
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2267
//    attempting to link to a field agree with the field's defining
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2268
//    class about the type of the field signature.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2269
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2270
//  * klassVtable::initialize_vtable requires that, when a class
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2271
//    overrides a vtable entry allocated by a superclass, that the
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2272
//    overriding method (i.e., the callee) agree with the superclass
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2273
//    on each type in the method's signature.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2274
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2275
//  * klassItable::initialize_itable requires that, when a class fills
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2276
//    in its itables, for each non-abstract method installed in an
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2277
//    itable, the method (i.e., the callee) agree with the interface
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2278
//    on each type in the method's signature.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2279
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2280
// All those methods have a boolean (check_access, checkconstraints)
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2281
// which turns off the checks.  This is used from specialized contexts
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2282
// such as bootstrapping, dumping, and debugging.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2283
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2284
// No direct constraint is placed between the class and its
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2285
// supertypes.  Constraints are only placed along linked relations
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2286
// between callers and callees.  When a method overrides or implements
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2287
// an abstract method in a supertype (superclass or interface), the
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2288
// constraints are placed as if the supertype were the caller to the
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2289
// overriding method.  (This works well, since callers to the
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2290
// supertype have already established agreement between themselves and
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2291
// the supertype.)  As a result of all this, a class can disagree with
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2292
// its supertype about the meaning of a type name, as long as that
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2293
// class neither calls a relevant method of the supertype, nor is
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2294
// called (perhaps via an override) from the supertype.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2295
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2296
//
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2297
// SystemDictionary::check_signature_loaders(sig, l1, l2)
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2298
//
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
// Make sure all class components (including arrays) in the given
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
// signature will be resolved to the same class in both loaders.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
// Returns the name of the type that failed a loader constraint check, or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
// NULL if no constraint failed. The returned C string needs cleaning up
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 2105
diff changeset
  2303
// with a ResourceMark in the caller.  No exception except OOME is thrown.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
char* SystemDictionary::check_signature_loaders(symbolHandle signature,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
                                               Handle loader1, Handle loader2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
                                               bool is_method, TRAPS)  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
  // Nothing to do if loaders are the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
  if (loader1() == loader2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  SignatureStream sig_strm(signature, is_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
  while (!sig_strm.is_done()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
    if (sig_strm.is_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
      symbolOop s = sig_strm.as_symbol(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
      symbolHandle sig (THREAD, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
      if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
        return sig()->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
    sig_strm.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2327
methodOop SystemDictionary::find_method_handle_invoke(symbolHandle signature,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2328
                                                      Handle class_loader,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2329
                                                      Handle protection_domain,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2330
                                                      TRAPS) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2331
  if (!EnableMethodHandles)  return NULL;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2332
  assert(class_loader.is_null() && protection_domain.is_null(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2333
         "cannot load specialized versions of MethodHandle.invoke");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2334
  if (invoke_method_table() == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2335
    // create this side table lazily
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2336
    _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2337
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2338
  unsigned int hash  = invoke_method_table()->compute_hash(signature);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2339
  int          index = invoke_method_table()->hash_to_index(hash);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2340
  SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2341
  if (spe == NULL || spe->property_oop() == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2342
    // Must create lots of stuff here, but outside of the SystemDictionary lock.
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4446
diff changeset
  2343
    if (THREAD->is_Compiler_thread())
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4446
diff changeset
  2344
      return NULL;              // do not attempt from within compiler
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2345
    Handle mt = compute_method_handle_type(signature(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2346
                                           class_loader, protection_domain,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2347
                                           CHECK_NULL);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2348
    KlassHandle  mh_klass = SystemDictionaryHandles::MethodHandle_klass();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2349
    methodHandle m = methodOopDesc::make_invoke_method(mh_klass, signature,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2350
                                                       mt, CHECK_NULL);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2351
    // Now grab the lock.  We might have to throw away the new method,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2352
    // if a racing thread has managed to install one at the same time.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2353
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2354
      MutexLocker ml(SystemDictionary_lock, Thread::current());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2355
      spe = invoke_method_table()->find_entry(index, hash, signature);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2356
      if (spe == NULL)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2357
        spe = invoke_method_table()->add_entry(index, hash, signature);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2358
      if (spe->property_oop() == NULL)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2359
        spe->set_property_oop(m());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2360
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2361
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2362
  methodOop m = (methodOop) spe->property_oop();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2363
  assert(m->is_method(), "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2364
  return m;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2365
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2366
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2367
// Ask Java code to find or construct a java.dyn.MethodType for the given
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2368
// signature, as interpreted relative to the given class loader.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2369
// Because of class loader constraints, all method handle usage must be
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2370
// consistent with this loader.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2371
Handle SystemDictionary::compute_method_handle_type(symbolHandle signature,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2372
                                                    Handle class_loader,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2373
                                                    Handle protection_domain,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2374
                                                    TRAPS) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2375
  Handle empty;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2376
  int npts = ArgumentCount(signature()).size();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2377
  objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::class_klass(), npts, CHECK_(empty));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2378
  int arg = 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2379
  Handle rt;                            // the return type from the signature
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2380
  for (SignatureStream ss(signature()); !ss.is_done(); ss.next()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2381
    oop mirror;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2382
    if (!ss.is_object()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2383
      mirror = Universe::java_mirror(ss.type());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2384
    } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2385
      symbolOop    name_oop = ss.as_symbol(CHECK_(empty));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2386
      symbolHandle name(THREAD, name_oop);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2387
      klassOop klass = resolve_or_fail(name,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2388
                                       class_loader, protection_domain,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2389
                                       true, CHECK_(empty));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2390
      mirror = Klass::cast(klass)->java_mirror();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2391
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2392
    if (ss.at_return_type())
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2393
      rt = Handle(THREAD, mirror);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2394
    else
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2395
      pts->obj_at_put(arg++, mirror);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2396
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2397
  assert(arg == npts, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2398
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2399
  // call MethodType java.dyn.MethodType::makeImpl(Class rt, Class[] pts, false, true)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2400
  bool varargs = false, trusted = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2401
  JavaCallArguments args(Handle(THREAD, rt()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2402
  args.push_oop(pts());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2403
  args.push_int(false);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2404
  args.push_int(trusted);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2405
  JavaValue result(T_OBJECT);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2406
  JavaCalls::call_static(&result,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2407
                         SystemDictionary::MethodType_klass(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2408
                         vmSymbols::makeImpl_name(), vmSymbols::makeImpl_signature(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2409
                         &args, CHECK_(empty));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2410
  return Handle(THREAD, (oop) result.get_jobject());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2411
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2412
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2332
diff changeset
  2413
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2414
// Ask Java code to find or construct a java.dyn.CallSite for the given
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2415
// name and signature, as interpreted relative to the given class loader.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2416
Handle SystemDictionary::make_dynamic_call_site(KlassHandle caller,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2417
                                                int caller_method_idnum,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2418
                                                int caller_bci,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2419
                                                symbolHandle name,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2420
                                                methodHandle mh_invdyn,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2421
                                                TRAPS) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2422
  Handle empty;
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2423
  // call java.dyn.CallSite::makeSite(caller, name, mtype, cmid, cbci)
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2424
  oop name_str_oop = StringTable::intern(name(), CHECK_(empty)); // not a handle!
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2425
  JavaCallArguments args(Handle(THREAD, caller->java_mirror()));
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2426
  args.push_oop(name_str_oop);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2427
  args.push_oop(mh_invdyn->method_handle_type());
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2428
  args.push_int(caller_method_idnum);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2429
  args.push_int(caller_bci);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2430
  JavaValue result(T_OBJECT);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2431
  JavaCalls::call_static(&result,
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2432
                         SystemDictionary::CallSite_klass(),
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2433
                         vmSymbols::makeSite_name(), vmSymbols::makeSite_signature(),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2434
                         &args, CHECK_(empty));
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2435
  oop call_site_oop = (oop) result.get_jobject();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 3575
diff changeset
  2436
  assert(call_site_oop->is_oop()
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2437
         /*&& java_dyn_CallSite::is_instance(call_site_oop)*/, "must be sane");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2438
  java_dyn_CallSite::set_vmmethod(call_site_oop, mh_invdyn());
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2439
  if (TraceMethodHandles) {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2440
#ifndef PRODUCT
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2441
    tty->print_cr("Linked invokedynamic bci=%d site="INTPTR_FORMAT":", caller_bci, call_site_oop);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2442
    call_site_oop->print();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2443
    tty->cr();
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2444
#endif //PRODUCT
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2445
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2446
  return call_site_oop;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2447
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2448
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2449
Handle SystemDictionary::find_bootstrap_method(KlassHandle caller,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2450
                                               KlassHandle search_bootstrap_klass,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2451
                                               TRAPS) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2452
  Handle empty;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2453
  if (!caller->oop_is_instance())  return empty;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2454
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2455
  instanceKlassHandle ik(THREAD, caller());
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2456
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2457
  oop boot_method_oop = ik->bootstrap_method();
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2458
  if (boot_method_oop != NULL) {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2459
    if (TraceMethodHandles) {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2460
      tty->print_cr("bootstrap method for "PTR_FORMAT" cached as "PTR_FORMAT":", ik(), boot_method_oop);
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2461
    }
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2462
    NOT_PRODUCT(if (!boot_method_oop->is_oop()) { tty->print_cr("*** boot MH of "PTR_FORMAT" = "PTR_FORMAT, ik(), boot_method_oop); ik()->print(); });
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2463
    assert(boot_method_oop->is_oop()
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2464
           && java_dyn_MethodHandle::is_instance(boot_method_oop), "must be sane");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2465
    return Handle(THREAD, boot_method_oop);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2466
  }
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2467
  boot_method_oop = NULL;  // GC safety
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2468
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2469
  // call java.dyn.Linkage::findBootstrapMethod(caller, sbk)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2470
  JavaCallArguments args(Handle(THREAD, ik->java_mirror()));
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2471
  if (search_bootstrap_klass.is_null())
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2472
    args.push_oop(Handle());
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2473
  else
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2474
    args.push_oop(search_bootstrap_klass->java_mirror());
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2475
  JavaValue result(T_OBJECT);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2476
  JavaCalls::call_static(&result,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2477
                         SystemDictionary::Linkage_klass(),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2478
                         vmSymbols::findBootstrapMethod_name(),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2479
                         vmSymbols::findBootstrapMethod_signature(),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2480
                         &args, CHECK_(empty));
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2481
  boot_method_oop = (oop) result.get_jobject();
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2482
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2483
  if (boot_method_oop != NULL) {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2484
    if (TraceMethodHandles) {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2485
#ifndef PRODUCT
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2486
      tty->print_cr("--------");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2487
      tty->print_cr("bootstrap method for "PTR_FORMAT" computed as "PTR_FORMAT":", ik(), boot_method_oop);
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2488
      ik()->print();
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2489
      boot_method_oop->print();
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2490
      tty->print_cr("========");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2491
#endif //PRODUCT
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2492
    }
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 3575
diff changeset
  2493
    assert(boot_method_oop->is_oop()
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 3575
diff changeset
  2494
           && java_dyn_MethodHandle::is_instance(boot_method_oop), "must be sane");
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2495
    // probably no race conditions, but let's be careful:
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2496
    if (Atomic::cmpxchg_ptr(boot_method_oop, ik->adr_bootstrap_method(), NULL) == NULL)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2497
      ik->set_bootstrap_method(boot_method_oop);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2498
    else
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2499
      boot_method_oop = ik->bootstrap_method();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2500
  } else {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2501
    if (TraceMethodHandles) {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2502
#ifndef PRODUCT
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2503
      tty->print_cr("--------");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2504
      tty->print_cr("bootstrap method for "PTR_FORMAT" computed as NULL:", ik());
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2505
      ik()->print();
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2506
      tty->print_cr("========");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2507
#endif //PRODUCT
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 4094
diff changeset
  2508
    }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2509
    boot_method_oop = ik->bootstrap_method();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2510
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2511
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2512
  return Handle(THREAD, boot_method_oop);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2513
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  2514
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2515
// Since the identity hash code for symbols changes when the symbols are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2516
// moved from the regular perm gen (hash in the mark word) to the shared
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2517
// spaces (hash is the address), the classes loaded into the dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2518
// may be in the wrong buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2519
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2520
void SystemDictionary::reorder_dictionary() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2521
  dictionary()->reorder_dictionary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2522
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2523
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2525
void SystemDictionary::copy_buckets(char** top, char* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2526
  dictionary()->copy_buckets(top, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2527
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2528
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2530
void SystemDictionary::copy_table(char** top, char* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2531
  dictionary()->copy_table(top, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2532
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2533
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2534
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2535
void SystemDictionary::reverse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2536
  dictionary()->reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2537
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2538
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2539
int SystemDictionary::number_of_classes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2540
  return dictionary()->number_of_entries();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2541
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2542
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2543
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2544
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2545
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2546
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2547
void SystemDictionary::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2548
  dictionary()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2549
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2550
  // Placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2551
  GCMutexLocker mu(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2552
  placeholders()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2553
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2554
  // loader constraints - print under SD_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2555
  constraints()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2556
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2557
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2558
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2559
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2560
void SystemDictionary::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2561
  guarantee(dictionary() != NULL, "Verify of system dictionary failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2562
  guarantee(constraints() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2563
            "Verify of loader constraints failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2564
  guarantee(dictionary()->number_of_entries() >= 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2565
            placeholders()->number_of_entries() >= 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2566
            "Verify of system dictionary failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2567
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2568
  // Verify dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2569
  dictionary()->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2570
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2571
  GCMutexLocker mu(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2572
  placeholders()->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2573
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2574
  // Verify constraint table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2575
  guarantee(constraints() != NULL, "Verify of loader constraints failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2576
  constraints()->verify(dictionary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2577
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2578
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2579
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2580
void SystemDictionary::verify_obj_klass_present(Handle obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2581
                                                symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2582
                                                Handle class_loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2583
  GCMutexLocker mu(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2584
  oop probe = find_class_or_placeholder(class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2585
  if (probe == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2586
    probe = SystemDictionary::find_shared_class(class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2587
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2588
  guarantee(probe != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2589
            (!probe->is_klass() || probe == obj()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2590
                     "Loaded klasses should be in SystemDictionary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2591
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2592
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2593
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2595
// statistics code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2596
class ClassStatistics: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2597
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2598
  static int nclasses;        // number of classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2599
  static int nmethods;        // number of methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2600
  static int nmethoddata;     // number of methodData
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2601
  static int class_size;      // size of class objects in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2602
  static int method_size;     // size of method objects in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2603
  static int debug_size;      // size of debug info in methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2604
  static int methoddata_size; // size of methodData objects in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2605
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2606
  static void do_class(klassOop k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2607
    nclasses++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2608
    class_size += k->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2609
    if (k->klass_part()->oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2610
      instanceKlass* ik = (instanceKlass*)k->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2611
      class_size += ik->methods()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2612
      class_size += ik->constants()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2613
      class_size += ik->local_interfaces()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2614
      class_size += ik->transitive_interfaces()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2615
      // We do not have to count implementors, since we only store one!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2616
      class_size += ik->fields()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2617
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2619
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2620
  static void do_method(methodOop m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2621
    nmethods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2622
    method_size += m->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2623
    // class loader uses same objArray for empty vectors, so don't count these
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2624
    if (m->exception_table()->length() != 0)   method_size += m->exception_table()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2625
    if (m->has_stackmap_table()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2626
      method_size += m->stackmap_data()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2627
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2628
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2629
    methodDataOop mdo = m->method_data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2630
    if (mdo != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2631
      nmethoddata++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2632
      methoddata_size += mdo->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2633
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2634
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2635
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2636
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2637
  static void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2638
    SystemDictionary::classes_do(do_class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2639
    SystemDictionary::methods_do(do_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2640
    tty->print_cr("Class statistics:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2641
    tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2642
    tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2643
                  (method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2644
    tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2645
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2646
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2647
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2648
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2649
int ClassStatistics::nclasses        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2650
int ClassStatistics::nmethods        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2651
int ClassStatistics::nmethoddata     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2652
int ClassStatistics::class_size      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2653
int ClassStatistics::method_size     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2654
int ClassStatistics::debug_size      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2655
int ClassStatistics::methoddata_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2657
void SystemDictionary::print_class_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2658
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2659
  ClassStatistics::print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2660
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2662
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2663
class MethodStatistics: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2664
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2665
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2666
    max_parameter_size = 10
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2667
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2668
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2669
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2670
  static int _number_of_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2671
  static int _number_of_final_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2672
  static int _number_of_static_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2673
  static int _number_of_native_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2674
  static int _number_of_synchronized_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2675
  static int _number_of_profiled_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2676
  static int _number_of_bytecodes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2677
  static int _parameter_size_profile[max_parameter_size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2678
  static int _bytecodes_profile[Bytecodes::number_of_java_codes];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2679
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2680
  static void initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2681
    _number_of_methods        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2682
    _number_of_final_methods  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2683
    _number_of_static_methods = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2684
    _number_of_native_methods = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2685
    _number_of_synchronized_methods = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2686
    _number_of_profiled_methods = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2687
    _number_of_bytecodes      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2688
    for (int i = 0; i < max_parameter_size             ; i++) _parameter_size_profile[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2689
    for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile     [j] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2690
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2691
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2692
  static void do_method(methodOop m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2693
    _number_of_methods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2694
    // collect flag info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2695
    if (m->is_final()       ) _number_of_final_methods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2696
    if (m->is_static()      ) _number_of_static_methods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2697
    if (m->is_native()      ) _number_of_native_methods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2698
    if (m->is_synchronized()) _number_of_synchronized_methods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2699
    if (m->method_data() != NULL) _number_of_profiled_methods++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2700
    // collect parameter size info (add one for receiver, if any)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2701
    _parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2702
    // collect bytecodes info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2703
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2704
      Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2705
      HandleMark hm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2706
      BytecodeStream s(methodHandle(thread, m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2707
      Bytecodes::Code c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2708
      while ((c = s.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2709
        _number_of_bytecodes++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2710
        _bytecodes_profile[c]++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2711
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2712
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2713
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2715
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2716
  static void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2717
    initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2718
    SystemDictionary::methods_do(do_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2719
    // generate output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2720
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2721
    tty->print_cr("Method statistics (static):");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2722
    // flag distribution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2723
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2724
    tty->print_cr("%6d final        methods  %6.1f%%", _number_of_final_methods       , _number_of_final_methods        * 100.0F / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2725
    tty->print_cr("%6d static       methods  %6.1f%%", _number_of_static_methods      , _number_of_static_methods       * 100.0F / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2726
    tty->print_cr("%6d native       methods  %6.1f%%", _number_of_native_methods      , _number_of_native_methods       * 100.0F / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2727
    tty->print_cr("%6d synchronized methods  %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2728
    tty->print_cr("%6d profiled     methods  %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2729
    // parameter size profile
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2730
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2731
    { int tot = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2732
      int avg = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2733
      for (int i = 0; i < max_parameter_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2734
        int n = _parameter_size_profile[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2735
        tot += n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2736
        avg += n*i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2737
        tty->print_cr("parameter size = %1d: %6d methods  %5.1f%%", i, n, n * 100.0F / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2738
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2739
      assert(tot == _number_of_methods, "should be the same");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2740
      tty->print_cr("                    %6d methods  100.0%%", _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2741
      tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2742
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2743
    // bytecodes profile
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2744
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2745
    { int tot = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2746
      for (int i = 0; i < Bytecodes::number_of_java_codes; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2747
        if (Bytecodes::is_defined(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2748
          Bytecodes::Code c = Bytecodes::cast(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2749
          int n = _bytecodes_profile[c];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2750
          tot += n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2751
          tty->print_cr("%9d  %7.3f%%  %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2752
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2753
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2754
      assert(tot == _number_of_bytecodes, "should be the same");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2755
      tty->print_cr("%9d  100.000%%", _number_of_bytecodes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2756
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2757
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2758
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2759
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2760
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2761
int MethodStatistics::_number_of_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2762
int MethodStatistics::_number_of_final_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2763
int MethodStatistics::_number_of_static_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2764
int MethodStatistics::_number_of_native_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2765
int MethodStatistics::_number_of_synchronized_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2766
int MethodStatistics::_number_of_profiled_methods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2767
int MethodStatistics::_number_of_bytecodes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2768
int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2769
int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2770
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2772
void SystemDictionary::print_method_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2773
  MethodStatistics::print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2774
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2775
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2776
#endif // PRODUCT