hotspot/src/share/vm/classfile/loaderConstraints.cpp
author ikrylov
Wed, 01 Dec 2010 18:26:32 -0500
changeset 7405 e6fc8d3926f8
parent 7397 5b173b4ca846
child 8076 96d498ec7ae1
permissions -rw-r--r--
6348631: remove the use of the HPI library from Hotspot Summary: move functions from hpi library to hotspot, communicate with licensees and open source community, check jdk for dependency, file CCC request Reviewed-by: coleenp, acorn, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2003, 2010, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/loaderConstraints.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/safepoint.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/hashtable.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
LoaderConstraintTable::LoaderConstraintTable(int nof_buckets)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  : Hashtable(nof_buckets, sizeof(LoaderConstraintEntry)) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
LoaderConstraintEntry* LoaderConstraintTable::new_entry(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                                 unsigned int hash, symbolOop name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                                 klassOop klass, int num_loaders,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                                 int max_loaders) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  LoaderConstraintEntry* entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  entry = (LoaderConstraintEntry*)Hashtable::new_entry(hash, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  entry->set_name(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  entry->set_num_loaders(num_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  entry->set_max_loaders(max_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void LoaderConstraintTable::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    for (LoaderConstraintEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      f->do_oop((oop*)(probe->name_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      if (probe->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        f->do_oop((oop*)probe->klass_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      for (int n = 0; n < probe->num_loaders(); n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
        if (probe->loader(n) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
          f->do_oop(probe->loader_addr(n));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// We must keep the symbolOop used in the name alive.  We'll use the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// loaders to decide if a particular entry can be purged.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
void LoaderConstraintTable::always_strong_classes_do(OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // We must keep the symbolOop used in the name alive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  for (int cindex = 0; cindex < table_size(); cindex++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    for (LoaderConstraintEntry* lc_probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                                lc_probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                                lc_probe = lc_probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      assert (lc_probe->name() != NULL,  "corrupted loader constraint table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      blk->do_oop((oop*)lc_probe->name_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    }
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
// The loaderConstraintTable must always be accessed with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// SystemDictionary lock held. This is true even for readers as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// entries in the table could be being dynamically resized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
                                    symbolHandle name, Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  unsigned int hash = compute_hash(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  LoaderConstraintEntry** pp = bucket_addr(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  while (*pp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    LoaderConstraintEntry* p = *pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    if (p->hash() == hash) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      if (p->name() == name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        for (int i = p->num_loaders() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
          if (p->loader(i) == loader()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
            return pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    pp = p->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  return pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void LoaderConstraintTable::purge_loader_constraints(BoolObjectClosure* is_alive) {
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 5124
diff changeset
   111
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Remove unloaded entries from constraint table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    LoaderConstraintEntry** p = bucket_addr(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    while(*p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      LoaderConstraintEntry* probe = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      klassOop klass = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      // Remove klass that is no longer alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      if (klass != NULL && !is_alive->do_object_b(klass)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        probe->set_klass(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
          ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
          tty->print_cr("[Purging class object from constraint for name %s,"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
                     " loader list:",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                     probe->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
          for (int i = 0; i < probe->num_loaders(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
            tty->print_cr("[   [%d]: %s", i,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                          SystemDictionary::loader_name(probe->loader(i)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      // Remove entries no longer alive from loader array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      while (n < probe->num_loaders()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        if (probe->loader(n) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
          if (!is_alive->do_object_b(probe->loader(n))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
            if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
              ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
              tty->print_cr("[Purging loader %s from constraint for name %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                            SystemDictionary::loader_name(probe->loader(n)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                            probe->name()->as_C_string()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                            );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
            // Compact array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
            int num = probe->num_loaders() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
            probe->set_num_loaders(num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
            probe->set_loader(n, probe->loader(num));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
            probe->set_loader(num, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
            if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
              ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
              tty->print_cr("[New loader list:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
              for (int i = 0; i < probe->num_loaders(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                tty->print_cr("[   [%d]: %s", i,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
                              SystemDictionary::loader_name(probe->loader(i)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
            continue;  // current element replaced, so restart without
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                       // incrementing n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        n++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      // Check whether entry should be purged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      if (probe->num_loaders() < 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
            if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
              ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
              tty->print("[Purging complete constraint for name %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                         probe->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        // Purge entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        *p = probe->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        FREE_C_HEAP_ARRAY(oop, probe->loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        free_entry(probe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        assert(is_alive->do_object_b(probe->name()), "name should be live");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        if (probe->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
          assert(is_alive->do_object_b(probe->klass()), "klass should be live");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        for (n = 0; n < probe->num_loaders(); n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
          if (probe->loader(n) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
            assert(is_alive->do_object_b(probe->loader(n)), "loader should be live");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        // Go to next entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        p = probe->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
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
bool LoaderConstraintTable::add_entry(symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                                      klassOop klass1, Handle class_loader1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
                                      klassOop klass2, Handle class_loader2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  int failure_code = 0; // encode different reasons for failing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  if (klass1 != NULL && klass2 != NULL && klass1 != klass2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    failure_code = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    klassOop klass = klass1 != NULL ? klass1 : klass2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    LoaderConstraintEntry** pp1 = find_loader_constraint(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                                                         class_loader1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    if (*pp1 != NULL && (*pp1)->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      if (klass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        if (klass != (*pp1)->klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
          failure_code = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        klass = (*pp1)->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    LoaderConstraintEntry** pp2 = find_loader_constraint(class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
                                                         class_loader2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    if (*pp2 != NULL && (*pp2)->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      if (klass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        if (klass != (*pp2)->klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
          failure_code = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        klass = (*pp2)->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    if (failure_code == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      if (*pp1 == NULL && *pp2 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        unsigned int hash = compute_hash(class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        LoaderConstraintEntry* p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        p = new_entry(hash, class_name(), klass, 2, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        p->set_loaders(NEW_C_HEAP_ARRAY(oop, 2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        p->set_loader(0, class_loader1());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        p->set_loader(1, class_loader2());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        p->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        p->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        set_entry(index, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
          ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
          tty->print("[Adding new constraint for name: %s, loader[0]: %s,"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
                     " loader[1]: %s ]\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
                     class_name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
                     SystemDictionary::loader_name(class_loader1()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                     SystemDictionary::loader_name(class_loader2())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                     );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      } else if (*pp1 == *pp2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        /* constraint already imposed */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        if ((*pp1)->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
          (*pp1)->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
          if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
            ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
            tty->print("[Setting class object in existing constraint for"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
                       " name: %s and loader %s ]\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                       class_name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
                       SystemDictionary::loader_name(class_loader1())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
                       );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
          assert((*pp1)->klass() == klass, "loader constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      } else if (*pp1 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
        extend_loader_constraint(*pp2, class_loader1, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      } else if (*pp2 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
        extend_loader_constraint(*pp1, class_loader2, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        merge_loader_constraints(pp1, pp2, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  if (failure_code != 0 && TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    const char* reason = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    switch(failure_code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    case 1: reason = "the class objects presented by loader[0] and loader[1]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
              " are different"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    case 2: reason = "the class object presented by loader[0] does not match"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
              " the stored class object in the constraint"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    case 3: reason = "the class object presented by loader[1] does not match"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
              " the stored class object in the constraint"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    default: reason = "unknown reason code";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    tty->print("[Failed to add constraint for name: %s, loader[0]: %s,"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
               " loader[1]: %s, Reason: %s ]\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
               class_name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
               SystemDictionary::loader_name(class_loader1()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
               SystemDictionary::loader_name(class_loader2()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
               reason
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
               );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  return failure_code == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
// return true if the constraint was updated, false if the constraint is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
// violated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
bool LoaderConstraintTable::check_or_update(instanceKlassHandle k,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
                                                   Handle loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
                                                   symbolHandle name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  LoaderConstraintEntry* p = *(find_loader_constraint(name, loader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  if (p && p->klass() != NULL && p->klass() != k()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      tty->print("[Constraint check failed for name %s, loader %s: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
                 "the presented class object differs from that stored ]\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
                 name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
                 SystemDictionary::loader_name(loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    if (p && p->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      p->set_klass(k());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
        tty->print("[Updating constraint for name %s, loader %s, "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
                   "by setting class object ]\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
                   name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
                   SystemDictionary::loader_name(loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
klassOop LoaderConstraintTable::find_constrained_klass(symbolHandle name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
                                                       Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  LoaderConstraintEntry *p = *(find_loader_constraint(name, loader));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  if (p != NULL && p->klass() != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    return p->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  // No constraints, or else no klass loaded yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
void LoaderConstraintTable::ensure_loader_constraint_capacity(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
                                                     LoaderConstraintEntry *p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
                                                    int nfree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    if (p->max_loaders() - p->num_loaders() < nfree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
        int n = nfree + p->num_loaders();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
        oop* new_loaders = NEW_C_HEAP_ARRAY(oop, n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
        memcpy(new_loaders, p->loaders(), sizeof(oop) * p->num_loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
        p->set_max_loaders(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
        FREE_C_HEAP_ARRAY(oop, p->loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
        p->set_loaders(new_loaders);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                                                     Handle loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
                                                     klassOop klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  ensure_loader_constraint_capacity(p, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  int num = p->num_loaders();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  p->set_loader(num, loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  p->set_num_loaders(num + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    tty->print("[Extending constraint for name %s by adding loader[%d]: %s %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
               p->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
               num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
               SystemDictionary::loader_name(loader()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
               (p->klass() == NULL ? " and setting class object ]\n" : " ]\n")
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
               );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  if (p->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    p->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    assert(klass == NULL || p->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
void LoaderConstraintTable::merge_loader_constraints(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                                                   LoaderConstraintEntry** pp1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
                                                   LoaderConstraintEntry** pp2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
                                                   klassOop klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // make sure *pp1 has higher capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  if ((*pp1)->max_loaders() < (*pp2)->max_loaders()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    LoaderConstraintEntry** tmp = pp2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    pp2 = pp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    pp1 = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  LoaderConstraintEntry* p1 = *pp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  LoaderConstraintEntry* p2 = *pp2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  ensure_loader_constraint_capacity(p1, p2->num_loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  for (int i = 0; i < p2->num_loaders(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    int num = p1->num_loaders();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    p1->set_loader(num, p2->loader(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    p1->set_num_loaders(num + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  if (TraceLoaderConstraints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    tty->print_cr("[Merged constraints for name %s, new loader list:",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
                  p1->name()->as_C_string()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
                  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    for (int i = 0; i < p1->num_loaders(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      tty->print_cr("[   [%d]: %s", i,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
                    SystemDictionary::loader_name(p1->loader(i)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    if (p1->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      tty->print_cr("[... and setting class object]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // p1->klass() will hold NULL if klass, p2->klass(), and old
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  // p1->klass() are all NULL.  In addition, all three must have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // matching non-NULL values, otherwise either the constraints would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // have been violated, or the constraints had been corrupted (and an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // assertion would fail).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  if (p2->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    assert(p2->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  if (p1->klass() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    p1->set_klass(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    assert(p1->klass() == klass, "constraints corrupted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  *pp2 = p2->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  FREE_C_HEAP_ARRAY(oop, p2->loaders());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  free_entry(p2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   438
void LoaderConstraintTable::verify(Dictionary* dictionary,
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   439
                                   PlaceholderTable* placeholders) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    for (LoaderConstraintEntry* probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
                                probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      guarantee(probe->name()->is_symbol(), "should be symbol");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      if (probe->klass() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        instanceKlass* ik = instanceKlass::cast(probe->klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        guarantee(ik->name() == probe->name(), "name should match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        symbolHandle name (thread, ik->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
        Handle loader(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
        unsigned int d_hash = dictionary->compute_hash(name, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
        int d_index = dictionary->hash_to_index(d_hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
        klassOop k = dictionary->find_class(d_index, d_hash, name, loader);
4899
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   454
        if (k != NULL) {
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   455
          // We found the class in the system dictionary, so we should
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   456
          // make sure that the klassOop matches what we already have.
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   457
          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
   458
        } else {
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   459
          // 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
   460
          // has to be in the placeholders table.
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   461
          unsigned int p_hash = placeholders->compute_hash(name, loader);
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   462
          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
   463
          PlaceholderEntry* entry = placeholders->get_entry(p_index, p_hash,
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   464
                                                            name, loader);
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   465
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   466
          // The instanceKlass might not be on the entry, so the only
ab225bac579c 6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents: 1
diff changeset
   467
          // 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
   468
          // 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
   469
          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
   470
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      for (int n = 0; n< probe->num_loaders(); n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
        guarantee(probe->loader(n)->is_oop_or_null(), "should be oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
// Called with the system dictionary lock held
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
void LoaderConstraintTable::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  tty->print_cr("Java loader constraints (entries=%d)", _loader_constraint_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    for (LoaderConstraintEntry* probe = bucket(cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
                                probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
                                probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      tty->print("%4d: ", cindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
      probe->name()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
      tty->print(" , loaders:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
      for (int n = 0; n < probe->num_loaders(); n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
        probe->loader(n)->print_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
        tty->print(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
#endif