src/hotspot/share/classfile/loaderConstraints.cpp
author kbarrett
Tue, 12 Jun 2018 18:12:59 -0400
changeset 50532 a18c60527166
parent 49821 02c08e20d66c
child 50634 c349d409262a
permissions -rw-r--r--
8204585: Remove IN_ARCHIVE_ROOT from Access API Summary: Replaced Access API with API on heap. Reviewed-by: jiangli, coleenp, tschatzl Contributed-by: stefan.karlsson@oracle.com, kim.barrett@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, 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"
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
    26
#include "classfile/dictionary.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    27
#include "classfile/classLoaderData.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/loaderConstraints.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
    29
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/safepoint.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/hashtable.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    36
void LoaderConstraintEntry::set_loader(int i, oop p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    37
  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
    38
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    39
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
    40
LoaderConstraintTable::LoaderConstraintTable(int table_size)
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
    41
  : Hashtable<InstanceKlass*, mtClass>(table_size, sizeof(LoaderConstraintEntry)) {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
LoaderConstraintEntry* LoaderConstraintTable::new_entry(
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    45
                                 unsigned int hash, Symbol* name,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    46
                                 InstanceKlass* klass, int num_loaders,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                                 int max_loaders) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  LoaderConstraintEntry* entry;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    49
  entry = (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::new_entry(hash, klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  entry->set_name(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  entry->set_num_loaders(num_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  entry->set_max_loaders(max_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    57
  // decrement name refcount before freeing
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
  entry->name()->decrement_refcount();
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    59
  Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    60
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// The loaderConstraintTable must always be accessed with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// SystemDictionary lock held. This is true even for readers as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// entries in the table could be being dynamically resized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint(
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    67
                                    Symbol* name, Handle loader) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  unsigned int hash = compute_hash(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  LoaderConstraintEntry** pp = bucket_addr(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    72
  ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(loader());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    73
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  while (*pp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    LoaderConstraintEntry* p = *pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    if (p->hash() == hash) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    77
      if (p->name() == name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        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
    79
          if (p->loader_data(i) == loader_data) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
            return pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    pp = p->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  return pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    91
void LoaderConstraintTable::purge_loader_constraints() {
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 5124
diff changeset
    92
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
    93
  LogTarget(Info, class, loader, constraints) lt;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Remove unloaded entries from constraint table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    LoaderConstraintEntry** p = bucket_addr(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    while(*p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      LoaderConstraintEntry* probe = *p;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
    99
      InstanceKlass* klass = probe->klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      // Remove klass that is no longer alive
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   101
      if (klass != NULL &&
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   102
          !klass->is_loader_alive()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        probe->set_klass(NULL);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   104
        if (lt.is_enabled()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
          ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   106
          lt.print("purging class object from constraint for name %s,"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                     " loader list:",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                     probe->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
          for (int i = 0; i < probe->num_loaders(); i++) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   110
            lt.print("    [%d]: %s", i,
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   111
                          probe->loader_data(i)->loader_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      // Remove entries no longer alive from loader array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      while (n < probe->num_loaders()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   118
        if (probe->loader_data(n)->is_unloading()) {
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   119
          if (lt.is_enabled()) {
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   120
            ResourceMark rm;
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   121
            lt.print("purging loader %s from constraint for name %s",
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   122
                     probe->loader_data(n)->loader_name(),
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   123
                     probe->name()->as_C_string()
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   124
                     );
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   125
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   127
          // Compact array
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   128
          int num = probe->num_loaders() - 1;
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   129
          probe->set_num_loaders(num);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   130
          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
   131
          probe->set_loader_data(num, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   133
          if (lt.is_enabled()) {
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   134
            ResourceMark rm;
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   135
            lt.print("new loader list:");
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   136
            for (int i = 0; i < probe->num_loaders(); i++) {
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   137
              lt.print("    [%d]: %s", i,
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   138
                            probe->loader_data(i)->loader_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
            }
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   140
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   142
          continue;  // current element replaced, so restart without
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   143
                     // incrementing n
1
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) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   149
            if (lt.is_enabled()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
              ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   151
              lt.print("purging complete constraint for name %s",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
                         probe->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        // Purge entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        *p = probe->next();
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 14588
diff changeset
   157
        FREE_C_HEAP_ARRAY(oop, probe->loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        free_entry(probe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        if (probe->klass() != NULL) {
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   162
          assert(probe->klass()->is_loader_alive(), "klass should be live");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        // Go to next entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        p = probe->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   172
void log_ldr_constraint_msg(Symbol* class_name, const char* reason,
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   173
                        Handle class_loader1, Handle class_loader2) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   174
  LogTarget(Info, class, loader, constraints) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   175
  if (lt.is_enabled()) {
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   176
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   177
    lt.print("Failed to add constraint for name: %s, loader[0]: %s,"
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   178
                " loader[1]: %s, Reason: %s",
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   179
                  class_name->as_C_string(),
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   180
                  SystemDictionary::loader_name(class_loader1()),
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   181
                  SystemDictionary::loader_name(class_loader2()),
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   182
                  reason);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   183
  }
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   184
}
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   185
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   186
bool LoaderConstraintTable::add_entry(Symbol* class_name,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   187
                                      InstanceKlass* klass1, Handle class_loader1,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   188
                                      InstanceKlass* klass2, Handle class_loader2) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   189
  LogTarget(Info, class, loader, constraints) lt;
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   190
  if (klass1 != NULL && klass2 != NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   191
    if (klass1 == klass2) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   192
      // Same type already loaded in both places.  There is no need for any constraint.
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   193
      return true;
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   194
    } else {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   195
      log_ldr_constraint_msg(class_name,
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   196
                             "The class objects presented by loader[0] and loader[1] "
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   197
                             "are different",
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   198
                             class_loader1, class_loader2);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   199
      return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   201
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   203
  InstanceKlass* klass = klass1 != NULL ? klass1 : klass2;
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   204
  LoaderConstraintEntry** pp1 = find_loader_constraint(class_name, class_loader1);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   205
  if (*pp1 != NULL && (*pp1)->klass() != NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   206
    if (klass != NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   207
      if (klass != (*pp1)->klass()) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   208
        log_ldr_constraint_msg(class_name,
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   209
                               "The class object presented by loader[0] does not match "
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   210
                               "the stored class object in the constraint",
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   211
                               class_loader1, class_loader2);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   212
        return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      }
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   214
    } else {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   215
      klass = (*pp1)->klass();
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   216
    }
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   217
  }
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   218
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   219
  LoaderConstraintEntry** pp2 = find_loader_constraint(class_name, class_loader2);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   220
  if (*pp2 != NULL && (*pp2)->klass() != NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   221
    if (klass != NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   222
      if (klass != (*pp2)->klass()) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   223
        log_ldr_constraint_msg(class_name,
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   224
                               "The class object presented by loader[1] does not match "
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   225
                               "the stored class object in the constraint",
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   226
                               class_loader1, class_loader2);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   227
        return false;
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   228
      }
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   229
    } else {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   230
      klass = (*pp2)->klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   234
  if (*pp1 == NULL && *pp2 == NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   235
    unsigned int hash = compute_hash(class_name);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   236
    int index = hash_to_index(hash);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   237
    LoaderConstraintEntry* p;
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   238
    p = new_entry(hash, class_name, klass, 2, 2);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   239
    p->set_loaders(NEW_C_HEAP_ARRAY(ClassLoaderData*, 2, mtClass));
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   240
    p->set_loader(0, class_loader1());
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   241
    p->set_loader(1, class_loader2());
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   242
    p->set_klass(klass);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   243
    p->set_next(bucket(index));
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   244
    set_entry(index, p);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   245
    if (lt.is_enabled()) {
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   246
      ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   247
      lt.print("adding new constraint for name: %s, loader[0]: %s,"
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   248
                    " loader[1]: %s",
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   249
                    class_name->as_C_string(),
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   250
                    SystemDictionary::loader_name(class_loader1()),
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   251
                    SystemDictionary::loader_name(class_loader2())
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   252
                    );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   254
  } else if (*pp1 == *pp2) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   255
    /* constraint already imposed */
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   256
    if ((*pp1)->klass() == NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   257
      (*pp1)->set_klass(klass);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   258
      if (lt.is_enabled()) {
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   259
        ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   260
        lt.print("setting class object in existing constraint for"
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   261
                      " name: %s and loader %s",
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   262
                      class_name->as_C_string(),
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   263
                      SystemDictionary::loader_name(class_loader1())
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   264
                      );
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   265
      }
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   266
    } else {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   267
      assert((*pp1)->klass() == klass, "loader constraints corrupted");
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   268
    }
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   269
  } else if (*pp1 == NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   270
    extend_loader_constraint(*pp2, class_loader1, klass);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   271
  } else if (*pp2 == NULL) {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   272
    extend_loader_constraint(*pp1, class_loader2, klass);
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   273
  } else {
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   274
    merge_loader_constraints(pp1, pp2, klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
46468
be80e262d2a2 8152295: Redundant CLCs for classes resolved in both loaders
hseigel
parents: 46380
diff changeset
   277
  return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
// return true if the constraint was updated, false if the constraint is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
// violated
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   283
bool LoaderConstraintTable::check_or_update(InstanceKlass* k,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   284
                                            Handle loader,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   285
                                            Symbol* name) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   286
  LogTarget(Info, class, loader, constraints) lt;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  LoaderConstraintEntry* p = *(find_loader_constraint(name, loader));
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   288
  if (p && p->klass() != NULL && p->klass() != k) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   289
    if (lt.is_enabled()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   291
      lt.print("constraint check failed for name %s, loader %s: "
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   292
                 "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
   293
                 name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
                 SystemDictionary::loader_name(loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    if (p && p->klass() == NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   299
      p->set_klass(k);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   300
      if (lt.is_enabled()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
        ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   302
        lt.print("updating constraint for name %s, loader %s, "
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   303
                   "by setting class object",
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   304
                   name->as_C_string(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
                   SystemDictionary::loader_name(loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   312
InstanceKlass* LoaderConstraintTable::find_constrained_klass(Symbol* name,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
                                                       Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  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
   315
  if (p != NULL && p->klass() != NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   316
    assert(p->klass()->is_instance_klass(), "sanity");
46716
53915543333d 8178107: Compiler crashes with "assert(get_instanceKlass()->is_loaded()) failed: must be at least loaded"
hseigel
parents: 46701
diff changeset
   317
    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
   318
      // 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
   319
      // 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
   320
      return NULL;
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
   321
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    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
   323
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // No constraints, or else no klass loaded yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
void LoaderConstraintTable::ensure_loader_constraint_capacity(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
                                                     LoaderConstraintEntry *p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                                                    int nfree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    if (p->max_loaders() - p->num_loaders() < nfree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
        int n = nfree + p->num_loaders();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   334
        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
   335
        memcpy(new_loaders, p->loaders(), sizeof(ClassLoaderData*) * p->num_loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
        p->set_max_loaders(n);
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 14588
diff changeset
   337
        FREE_C_HEAP_ARRAY(ClassLoaderData*, p->loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
        p->set_loaders(new_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
                                                     Handle loader,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   345
                                                     InstanceKlass* klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  ensure_loader_constraint_capacity(p, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  int num = p->num_loaders();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  p->set_loader(num, loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  p->set_num_loaders(num + 1);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   350
  LogTarget(Info, class, loader, constraints) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   351
  if (lt.is_enabled()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   353
    lt.print("extending constraint for name %s by adding loader[%d]: %s %s",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
               p->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
               num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
               SystemDictionary::loader_name(loader()),
37202
4100f25e4b09 8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents: 33611
diff changeset
   357
               (p->klass() == NULL ? " and setting class object" : "")
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
               );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  if (p->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    p->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    assert(klass == NULL || p->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
void LoaderConstraintTable::merge_loader_constraints(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
                                                   LoaderConstraintEntry** pp1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                                                   LoaderConstraintEntry** pp2,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   371
                                                   InstanceKlass* klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // make sure *pp1 has higher capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  if ((*pp1)->max_loaders() < (*pp2)->max_loaders()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    LoaderConstraintEntry** tmp = pp2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    pp2 = pp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    pp1 = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  LoaderConstraintEntry* p1 = *pp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  LoaderConstraintEntry* p2 = *pp2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  ensure_loader_constraint_capacity(p1, p2->num_loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  for (int i = 0; i < p2->num_loaders(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    int num = p1->num_loaders();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   386
    p1->set_loader_data(num, p2->loader_data(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    p1->set_num_loaders(num + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   390
  LogTarget(Info, class, loader, constraints) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   391
  if (lt.is_enabled()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   393
    lt.print("merged constraints for name %s, new loader list:",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
                  p1->name()->as_C_string()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
                  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    for (int i = 0; i < p1->num_loaders(); i++) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   398
      lt.print("    [%d]: %s", i,
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   399
                    p1->loader_data(i)->loader_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    if (p1->klass() == NULL) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46468
diff changeset
   402
      lt.print("... and setting class object");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  // p1->klass() will hold NULL if klass, p2->klass(), and old
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  // p1->klass() are all NULL.  In addition, all three must have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // matching non-NULL values, otherwise either the constraints would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // have been violated, or the constraints had been corrupted (and an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // assertion would fail).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  if (p2->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    assert(p2->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  if (p1->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    p1->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    assert(p1->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  *pp2 = p2->next();
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 14588
diff changeset
   421
  FREE_C_HEAP_ARRAY(oop, p2->loaders());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  free_entry(p2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   427
void LoaderConstraintTable::verify(PlaceholderTable* placeholders) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  Thread *thread = Thread::current();
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   429
  for (int cindex = 0; cindex < table_size(); cindex++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    for (LoaderConstraintEntry* probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
                                probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
      if (probe->klass() != NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 38151
diff changeset
   434
        InstanceKlass* ik = probe->klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
        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
   436
        Symbol* name = ik->name();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   437
        ClassLoaderData* loader_data = ik->class_loader_data();
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   438
        Dictionary* dictionary = loader_data->dictionary();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   439
        unsigned int d_hash = dictionary->compute_hash(name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
        int d_index = dictionary->hash_to_index(d_hash);
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   441
        InstanceKlass* k = dictionary->find_class(d_index, d_hash, name);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   442
        if (k != NULL) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   443
          // We found the class in the dictionary, so we should
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   444
          // 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
   445
          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
   446
        } else {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   447
          // If we don't find the class in the dictionary, it
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   448
          // has to be in the placeholders table.
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   449
          unsigned int p_hash = placeholders->compute_hash(name);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   450
          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
   451
          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
   452
                                                            name, loader_data);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   453
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   454
          // 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
   455
          // 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
   456
          // 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
   457
          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
   458
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      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
   461
        assert(ClassLoaderDataGraph::contains_loader_data(probe->loader_data(n)), "The loader is missing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
// Called with the system dictionary lock held
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   468
void LoaderConstraintTable::print_on(outputStream* st) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  assert_locked_or_safepoint(SystemDictionary_lock);
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   471
  st->print_cr("Java loader constraints (table_size=%d, constraints=%d)",
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   472
               table_size(), number_of_entries());
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46716
diff changeset
   473
  for (int cindex = 0; cindex < table_size(); cindex++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    for (LoaderConstraintEntry* probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
                                probe = probe->next()) {
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   477
      st->print("%4d: ", cindex);
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   478
      probe->name()->print_on(st);
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   479
      st->print(" , loaders:");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
      for (int n = 0; n < probe->num_loaders(); n++) {
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   481
        probe->loader_data(n)->print_value_on(st);
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   482
        st->print(", ");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
      }
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   484
      st->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
}