hotspot/src/share/vm/classfile/loaderConstraints.cpp
author coleenp
Wed, 12 Apr 2017 08:02:29 -0400
changeset 46380 4a51438196cf
parent 46329 53ccc37bda19
child 46468 be80e262d2a2
permissions -rw-r--r--
8026985: Rewrite SystemDictionary::classes_do and Dictionary::classes_do to use KlassClosure Summary: Actually remove unused functions like classes_do and methods_do. Reviewed-by: iveresov, sspitsyn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    26
#include "classfile/classLoaderData.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/loaderConstraints.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/safepoint.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/hashtable.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    34
void LoaderConstraintEntry::set_loader(int i, oop p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    35
  set_loader_data(i, ClassLoaderData::class_loader_data(p));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    36
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    37
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
LoaderConstraintTable::LoaderConstraintTable(int nof_buckets)
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    39
  : Hashtable<InstanceKlass*, mtClass>(nof_buckets, sizeof(LoaderConstraintEntry)) {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
LoaderConstraintEntry* LoaderConstraintTable::new_entry(
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    43
                                 unsigned int hash, Symbol* name,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    44
                                 InstanceKlass* klass, int num_loaders,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                 int max_loaders) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  LoaderConstraintEntry* entry;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    47
  entry = (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::new_entry(hash, klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  entry->set_name(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  entry->set_num_loaders(num_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  entry->set_max_loaders(max_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    54
void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    55
  // decrement name refcount before freeing
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
  entry->name()->decrement_refcount();
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    57
  Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    59
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// The loaderConstraintTable must always be accessed with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// SystemDictionary lock held. This is true even for readers as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// entries in the table could be being dynamically resized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint(
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    65
                                    Symbol* name, Handle loader) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  unsigned int hash = compute_hash(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  LoaderConstraintEntry** pp = bucket_addr(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    70
  ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(loader());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    71
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  while (*pp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    LoaderConstraintEntry* p = *pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (p->hash() == hash) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    75
      if (p->name() == name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        for (int i = p->num_loaders() - 1; i >= 0; i--) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    77
          if (p->loader_data(i) == loader_data) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
            return pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    pp = p->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  return pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    89
void LoaderConstraintTable::purge_loader_constraints() {
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 5124
diff changeset
    90
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Remove unloaded entries from constraint table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    LoaderConstraintEntry** p = bucket_addr(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    while(*p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      LoaderConstraintEntry* probe = *p;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    96
      InstanceKlass* klass = probe->klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      // Remove klass that is no longer alive
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    98
      if (klass != NULL &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    99
          klass->class_loader_data()->is_unloading()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        probe->set_klass(NULL);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   101
        if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
          ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   103
          outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   104
          out->print_cr("purging class object from constraint for name %s,"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                     " loader list:",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                     probe->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
          for (int i = 0; i < probe->num_loaders(); i++) {
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   108
            out->print_cr("    [%d]: %s", i,
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   109
                          probe->loader_data(i)->loader_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      // Remove entries no longer alive from loader array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      while (n < probe->num_loaders()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   116
        if (probe->loader_data(n)->is_unloading()) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   117
            if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
              ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   119
              outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   120
              out->print_cr("purging loader %s from constraint for name %s",
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   121
                            probe->loader_data(n)->loader_name(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
                            probe->name()->as_C_string()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
                            );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
            // Compact array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
            int num = probe->num_loaders() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
            probe->set_num_loaders(num);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   129
          probe->set_loader_data(n, probe->loader_data(num));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   130
          probe->set_loader_data(num, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   132
            if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
              ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   134
              outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   135
              out->print_cr("new loader list:");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
              for (int i = 0; i < probe->num_loaders(); i++) {
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   137
                out->print_cr("    [%d]: %s", i,
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   138
                              probe->loader_data(i)->loader_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
            continue;  // current element replaced, so restart without
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
                       // incrementing n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        n++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // Check whether entry should be purged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if (probe->num_loaders() < 2) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   149
            if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
              ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   151
              outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   152
              out->print_cr("purging complete constraint for name %s",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                         probe->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        // Purge entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        *p = probe->next();
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 14588
diff changeset
   158
        FREE_C_HEAP_ARRAY(oop, probe->loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        free_entry(probe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        if (probe->klass() != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   163
          ClassLoaderData* loader_data =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   164
            probe->klass()->class_loader_data();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   165
          assert(!loader_data->is_unloading(), "klass should be live");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        // Go to next entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        p = probe->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   175
bool LoaderConstraintTable::add_entry(Symbol* class_name,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   176
                                      InstanceKlass* klass1, Handle class_loader1,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   177
                                      InstanceKlass* klass2, Handle class_loader2) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  int failure_code = 0; // encode different reasons for failing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if (klass1 != NULL && klass2 != NULL && klass1 != klass2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    failure_code = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  } else {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   183
    InstanceKlass* klass = klass1 != NULL ? klass1 : klass2;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    LoaderConstraintEntry** pp1 = find_loader_constraint(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                                                         class_loader1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    if (*pp1 != NULL && (*pp1)->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      if (klass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        if (klass != (*pp1)->klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
          failure_code = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        klass = (*pp1)->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    LoaderConstraintEntry** pp2 = find_loader_constraint(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                                                         class_loader2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (*pp2 != NULL && (*pp2)->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      if (klass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        if (klass != (*pp2)->klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
          failure_code = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        klass = (*pp2)->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    if (failure_code == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      if (*pp1 == NULL && *pp2 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        unsigned int hash = compute_hash(class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        LoaderConstraintEntry* p;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   214
        p = new_entry(hash, class_name, klass, 2, 2);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   215
        p->set_loaders(NEW_C_HEAP_ARRAY(ClassLoaderData*, 2, mtClass));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        p->set_loader(0, class_loader1());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        p->set_loader(1, class_loader2());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        p->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        p->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        set_entry(index, p);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   221
        if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
          ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   223
          outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   224
          out->print_cr("adding new constraint for name: %s, loader[0]: %s,"
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   225
                     " loader[1]: %s",
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   226
                     class_name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
                     SystemDictionary::loader_name(class_loader1()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
                     SystemDictionary::loader_name(class_loader2())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
                     );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      } else if (*pp1 == *pp2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        /* constraint already imposed */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        if ((*pp1)->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          (*pp1)->set_klass(klass);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   235
          if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
            ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   237
            outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   238
            out->print_cr("setting class object in existing constraint for"
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   239
                       " name: %s and loader %s",
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   240
                       class_name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
                       SystemDictionary::loader_name(class_loader1())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
                       );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
          assert((*pp1)->klass() == klass, "loader constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      } else if (*pp1 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        extend_loader_constraint(*pp2, class_loader1, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      } else if (*pp2 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        extend_loader_constraint(*pp1, class_loader2, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        merge_loader_constraints(pp1, pp2, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   257
  if (failure_code != 0 && log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   259
    outputStream* out = Log(class, loader, constraints)::info_stream();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    const char* reason = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    switch(failure_code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    case 1: reason = "the class objects presented by loader[0] and loader[1]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
              " are different"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    case 2: reason = "the class object presented by loader[0] does not match"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
              " the stored class object in the constraint"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    case 3: reason = "the class object presented by loader[1] does not match"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
              " the stored class object in the constraint"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    default: reason = "unknown reason code";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    }
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   270
    out->print_cr("failed to add constraint for name: %s, loader[0]: %s,"
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   271
               " loader[1]: %s, Reason: %s",
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   272
               class_name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
               SystemDictionary::loader_name(class_loader1()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
               SystemDictionary::loader_name(class_loader2()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
               reason
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
               );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  return failure_code == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
// return true if the constraint was updated, false if the constraint is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
// violated
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   285
bool LoaderConstraintTable::check_or_update(InstanceKlass* k,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   286
                                            Handle loader,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   287
                                            Symbol* name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  LoaderConstraintEntry* p = *(find_loader_constraint(name, loader));
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   289
  if (p && p->klass() != NULL && p->klass() != k) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   290
    if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   292
      outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   293
      out->print_cr("constraint check failed for name %s, loader %s: "
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   294
                 "the presented class object differs from that stored",
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   295
                 name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
                 SystemDictionary::loader_name(loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    if (p && p->klass() == NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   301
      p->set_klass(k);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   302
      if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
        ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   304
        outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   305
        out->print_cr("updating constraint for name %s, loader %s, "
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   306
                   "by setting class object",
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   307
                   name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
                   SystemDictionary::loader_name(loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   315
InstanceKlass* LoaderConstraintTable::find_constrained_klass(Symbol* name,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
                                                       Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  LoaderConstraintEntry *p = *(find_loader_constraint(name, loader));
8314
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   318
  if (p != NULL && p->klass() != NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   319
    assert(p->klass()->is_instance_klass(), "sanity");
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   320
    if (p->klass()->is_loaded()) {
8314
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   321
      // Only return fully loaded classes.  Classes found through the
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   322
      // constraints might still be in the process of loading.
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   323
      return NULL;
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   324
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    return p->klass();
8314
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   326
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // No constraints, or else no klass loaded yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
void LoaderConstraintTable::ensure_loader_constraint_capacity(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
                                                     LoaderConstraintEntry *p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
                                                    int nfree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    if (p->max_loaders() - p->num_loaders() < nfree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
        int n = nfree + p->num_loaders();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   337
        ClassLoaderData** new_loaders = NEW_C_HEAP_ARRAY(ClassLoaderData*, n, mtClass);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   338
        memcpy(new_loaders, p->loaders(), sizeof(ClassLoaderData*) * p->num_loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
        p->set_max_loaders(n);
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 14588
diff changeset
   340
        FREE_C_HEAP_ARRAY(ClassLoaderData*, p->loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
        p->set_loaders(new_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                                                     Handle loader,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   348
                                                     InstanceKlass* klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  ensure_loader_constraint_capacity(p, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  int num = p->num_loaders();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  p->set_loader(num, loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  p->set_num_loaders(num + 1);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   353
  if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   355
    outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   356
    out->print_cr("extending constraint for name %s by adding loader[%d]: %s %s",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
               p->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
               num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
               SystemDictionary::loader_name(loader()),
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   360
               (p->klass() == NULL ? " and setting class object" : "")
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
               );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  if (p->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    p->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    assert(klass == NULL || p->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
void LoaderConstraintTable::merge_loader_constraints(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                                                   LoaderConstraintEntry** pp1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                                                   LoaderConstraintEntry** pp2,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   374
                                                   InstanceKlass* klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // make sure *pp1 has higher capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  if ((*pp1)->max_loaders() < (*pp2)->max_loaders()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    LoaderConstraintEntry** tmp = pp2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    pp2 = pp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    pp1 = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  LoaderConstraintEntry* p1 = *pp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  LoaderConstraintEntry* p2 = *pp2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  ensure_loader_constraint_capacity(p1, p2->num_loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  for (int i = 0; i < p2->num_loaders(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    int num = p1->num_loaders();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   389
    p1->set_loader_data(num, p2->loader_data(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    p1->set_num_loaders(num + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   393
  if (log_is_enabled(Info, class, loader, constraints)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    ResourceMark rm;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37242
diff changeset
   395
    outputStream* out = Log(class, loader, constraints)::info_stream();
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   396
    out->print_cr("merged constraints for name %s, new loader list:",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
                  p1->name()->as_C_string()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
                  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    for (int i = 0; i < p1->num_loaders(); i++) {
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   401
      out->print_cr("    [%d]: %s", i,
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   402
                    p1->loader_data(i)->loader_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    if (p1->klass() == NULL) {
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   405
      out->print_cr("... and setting class object");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // p1->klass() will hold NULL if klass, p2->klass(), and old
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // p1->klass() are all NULL.  In addition, all three must have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  // matching non-NULL values, otherwise either the constraints would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // have been violated, or the constraints had been corrupted (and an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // assertion would fail).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  if (p2->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    assert(p2->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  if (p1->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    p1->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    assert(p1->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  *pp2 = p2->next();
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 14588
diff changeset
   424
  FREE_C_HEAP_ARRAY(oop, p2->loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  free_entry(p2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   430
void LoaderConstraintTable::verify(Dictionary* dictionary,
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   431
                                   PlaceholderTable* placeholders) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    for (LoaderConstraintEntry* probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
                                probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      if (probe->klass() != NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   438
        InstanceKlass* ik = probe->klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
        guarantee(ik->name() == probe->name(), "name should match");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   440
        Symbol* name = ik->name();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   441
        ClassLoaderData* loader_data = ik->class_loader_data();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   442
        unsigned int d_hash = dictionary->compute_hash(name, loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
        int d_index = dictionary->hash_to_index(d_hash);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   444
        InstanceKlass* k = dictionary->find_class(d_index, d_hash, name, loader_data);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   445
        if (k != NULL) {
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   446
          // We found the class in the system dictionary, so we should
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   447
          // make sure that the Klass* matches what we already have.
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   448
          guarantee(k == probe->klass(), "klass should be in dictionary");
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   449
        } else {
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   450
          // If we don't find the class in the system dictionary, it
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   451
          // has to be in the placeholders table.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   452
          unsigned int p_hash = placeholders->compute_hash(name, loader_data);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   453
          int p_index = placeholders->hash_to_index(p_hash);
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   454
          PlaceholderEntry* entry = placeholders->get_entry(p_index, p_hash,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   455
                                                            name, loader_data);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   456
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   457
          // The InstanceKlass might not be on the entry, so the only
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   458
          // thing we can check here is whether we were successful in
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   459
          // finding the class in the placeholders table.
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   460
          guarantee(entry != NULL, "klass should be in the placeholders");
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   461
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      for (int n = 0; n< probe->num_loaders(); n++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   464
        assert(ClassLoaderDataGraph::contains_loader_data(probe->loader_data(n)), "The loader is missing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
// Called with the system dictionary lock held
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
void LoaderConstraintTable::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  tty->print_cr("Java loader constraints (entries=%d)", _loader_constraint_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    for (LoaderConstraintEntry* probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
                                probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      tty->print("%4d: ", cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
      probe->name()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
      tty->print(" , loaders:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
      for (int n = 0; n < probe->num_loaders(); n++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   485
        probe->loader_data(n)->print_value();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
        tty->print(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
#endif