src/hotspot/share/oops/instanceRefKlass.cpp
author coleenp
Wed, 24 Jul 2019 10:22:11 -0400
changeset 57511 00ae3b739184
parent 50277 f84ae8aa5d88
permissions -rw-r--r--
8228485: JVM crashes when bootstrap method for condy triggers loading of class whose static initializer throws exception Summary: Add case for JVM_CONSTANT_Dynamic in error_message function. Reviewed-by: dholmes, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 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: 4573
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4573
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: 4573
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: 6248
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    26
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    27
#include "classfile/systemDictionary.hpp"
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29792
diff changeset
    28
#include "oops/instanceRefKlass.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6248
diff changeset
    29
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
13738
d67be49a5beb 7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents: 13728
diff changeset
    31
void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // Clear the nonstatic oop-map entries corresponding to referent
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    33
  // and discovered fields.  They are treated specially by the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // garbage collector.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12780
diff changeset
    35
  InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // Check that we have the right class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  debug_only(static bool first_time = true);
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
    39
  assert(k == SystemDictionary::Reference_klass() && first_time,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
         "Invalid update of maps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  debug_only(first_time = false);
3693
af387bf37e8d 6861660: OopMapBlock count/size confusion
jcoomes
parents: 3262
diff changeset
    42
  assert(ik->nonstatic_oop_map_count() == 1, "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    46
#ifdef ASSERT
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    47
  // Verify fields are in the expected places.
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    48
  int referent_offset = java_lang_ref_Reference::referent_offset;
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    49
  int queue_offset = java_lang_ref_Reference::queue_offset;
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    50
  int next_offset = java_lang_ref_Reference::next_offset;
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    51
  int discovered_offset = java_lang_ref_Reference::discovered_offset;
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    52
  assert(referent_offset < queue_offset, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    53
  assert(queue_offset < next_offset, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    54
  assert(next_offset < discovered_offset, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    55
  const unsigned int count =
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    56
    1 + ((discovered_offset - referent_offset) / heapOopSize);
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    57
  assert(count == 4, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    58
#endif // ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    60
  // Updated map starts at "queue", covers "queue" and "next".
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    61
  const int new_offset = java_lang_ref_Reference::queue_offset;
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    62
  const unsigned int new_count = 2; // queue and next
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    63
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    64
  // Verify existing map is as expected, and update if needed.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if (UseSharedSpaces) {
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    66
    assert(map->offset() == new_offset, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    67
    assert(map->count() == new_count, "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  } else {
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    69
    assert(map->offset() == referent_offset, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    70
    assert(map->count() == count, "just checking");
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    71
    map->set_offset(new_offset);
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    72
    map->set_count(new_count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// Verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
13738
d67be49a5beb 7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents: 13728
diff changeset
    79
void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12780
diff changeset
    80
  InstanceKlass::oop_verify_on(obj, st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Verify referent field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  oop referent = java_lang_ref_Reference::referent(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (referent != NULL) {
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 37129
diff changeset
    84
    guarantee(oopDesc::is_oop(referent), "referent field heap failed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
50277
f84ae8aa5d88 8203028: Simplify reference processing in light of JDK-8175797
kbarrett
parents: 47216
diff changeset
    86
  // Additional verification for next field, which must be a Reference or null
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  oop next = java_lang_ref_Reference::next(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  if (next != NULL) {
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 37129
diff changeset
    89
    guarantee(oopDesc::is_oop(next), "next field should be an oop");
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33148
diff changeset
    90
    guarantee(next->is_instance(), "next field should be an instance");
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33148
diff changeset
    91
    guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}