hotspot/src/share/vm/oops/instanceRefKlass.cpp
author coleenp
Wed, 23 Aug 2017 14:52:55 -0400
changeset 46968 9119841280f4
parent 37129 af29e306e50b
permissions -rw-r--r--
8160399: is_oop_or_null involves undefined behavior 8164984: Improper use of is_oop in production code Summary: replace oop->is_oop*() with oopDesc::is_oop*(oop) so this pointer can be verified Reviewed-by: iklam, kvn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 37129
diff changeset
     2
 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // and nextPending field.  They are treated specially by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // garbage collector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // The discovered field is used only by the garbage collector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // and is also treated specially.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12780
diff changeset
    37
  InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // Check that we have the right class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  debug_only(static bool first_time = true);
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3795
diff changeset
    41
  assert(k == SystemDictionary::Reference_klass() && first_time,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
         "Invalid update of maps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  debug_only(first_time = false);
3693
af387bf37e8d 6861660: OopMapBlock count/size confusion
jcoomes
parents: 3262
diff changeset
    44
  assert(ik->nonstatic_oop_map_count() == 1, "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Check that the current map is (2,4) - currently points at field with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // offset 2 (words) and has 4 map entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  debug_only(int offset = java_lang_ref_Reference::referent_offset);
3694
942b7bc7f28c 6845368: large objects cause a crash or unexpected exception
jcoomes
parents: 3693
diff changeset
    51
  debug_only(unsigned int count = ((java_lang_ref_Reference::discovered_offset -
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    52
    java_lang_ref_Reference::referent_offset)/heapOopSize) + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  if (UseSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    assert(map->offset() == java_lang_ref_Reference::queue_offset &&
3693
af387bf37e8d 6861660: OopMapBlock count/size confusion
jcoomes
parents: 3262
diff changeset
    56
           map->count() == 1, "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  } else {
3693
af387bf37e8d 6861660: OopMapBlock count/size confusion
jcoomes
parents: 3262
diff changeset
    58
    assert(map->offset() == offset && map->count() == count,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
           "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    // Update map to (3,1) - point to offset of 3 (words) with 1 map entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    map->set_offset(java_lang_ref_Reference::queue_offset);
3693
af387bf37e8d 6861660: OopMapBlock count/size confusion
jcoomes
parents: 3262
diff changeset
    63
    map->set_count(1);
1
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
// Verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
13738
d67be49a5beb 7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents: 13728
diff changeset
    70
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
    71
  InstanceKlass::oop_verify_on(obj, st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Verify referent field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  oop referent = java_lang_ref_Reference::referent(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (referent != NULL) {
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 37129
diff changeset
    75
    guarantee(oopDesc::is_oop(referent), "referent field heap failed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Verify next field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  oop next = java_lang_ref_Reference::next(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  if (next != NULL) {
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 37129
diff changeset
    80
    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
    81
    guarantee(next->is_instance(), "next field should be an instance");
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33148
diff changeset
    82
    guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}