src/share/vm/oops/arrayOop.hpp

Thu, 07 Apr 2011 09:53:20 -0700

author
johnc
date
Thu, 07 Apr 2011 09:53:20 -0700
changeset 2781
e1162778c1c8
parent 2314
f95d63e2154a
child 3266
6fd81579526f
permissions
-rw-r--r--

7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
Summary: A referent object that is only weakly reachable at the start of concurrent marking but is re-attached to the strongly reachable object graph during marking may not be marked as live. This can cause the reference object to be processed prematurely and leave dangling pointers to the referent object. Implement a read barrier for the java.lang.ref.Reference::referent field by intrinsifying the Reference.get() method, and intercepting accesses though JNI, reflection, and Unsafe, so that when a non-null referent object is read it is also logged in an SATB buffer.
Reviewed-by: kvn, iveresov, never, tonyp, dholmes

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OOPS_ARRAYOOP_HPP
stefank@2314 26 #define SHARE_VM_OOPS_ARRAYOOP_HPP
stefank@2314 27
stefank@2314 28 #include "memory/universe.inline.hpp"
stefank@2314 29 #include "oops/oop.hpp"
stefank@2314 30
coleenp@548 31 // arrayOopDesc is the abstract baseclass for all arrays. It doesn't
coleenp@548 32 // declare pure virtual to enforce this because that would allocate a vtbl
coleenp@548 33 // in each instance, which we don't want.
coleenp@548 34
coleenp@548 35 // The layout of array Oops is:
coleenp@548 36 //
coleenp@548 37 // markOop
coleenp@548 38 // klassOop // 32 bits if compressed but declared 64 in LP64.
coleenp@548 39 // length // shares klass memory or allocated after declared fields.
coleenp@548 40
duke@435 41
duke@435 42 class arrayOopDesc : public oopDesc {
duke@435 43 friend class VMStructs;
coleenp@548 44
coleenp@548 45 // Interpreter/Compiler offsets
coleenp@548 46
coleenp@548 47 // Header size computation.
coleenp@548 48 // The header is considered the oop part of this type plus the length.
coleenp@548 49 // Returns the aligned header_size_in_bytes. This is not equivalent to
kvn@600 50 // sizeof(arrayOopDesc) which should not appear in the code.
coleenp@548 51 static int header_size_in_bytes() {
kvn@600 52 size_t hs = align_size_up(length_offset_in_bytes() + sizeof(int),
kvn@600 53 HeapWordSize);
coleenp@548 54 #ifdef ASSERT
coleenp@548 55 // make sure it isn't called before UseCompressedOops is initialized.
coleenp@548 56 static size_t arrayoopdesc_hs = 0;
coleenp@548 57 if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
coleenp@548 58 assert(arrayoopdesc_hs == hs, "header size can't change");
coleenp@548 59 #endif // ASSERT
coleenp@548 60 return (int)hs;
coleenp@548 61 }
duke@435 62
duke@435 63 public:
coleenp@548 64 // The _length field is not declared in C++. It is allocated after the
coleenp@548 65 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
coleenp@548 66 // it occupies the second half of the _klass field in oopDesc.
coleenp@548 67 static int length_offset_in_bytes() {
coleenp@548 68 return UseCompressedOops ? klass_gap_offset_in_bytes() :
coleenp@548 69 sizeof(arrayOopDesc);
coleenp@548 70 }
coleenp@548 71
coleenp@548 72 // Returns the offset of the first element.
coleenp@548 73 static int base_offset_in_bytes(BasicType type) {
coleenp@548 74 return header_size(type) * HeapWordSize;
coleenp@548 75 }
duke@435 76
duke@435 77 // Returns the address of the first element.
coleenp@548 78 void* base(BasicType type) const {
coleenp@548 79 return (void*) (((intptr_t) this) + base_offset_in_bytes(type));
coleenp@548 80 }
duke@435 81
duke@435 82 // Tells whether index is within bounds.
duke@435 83 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
duke@435 84
coleenp@548 85 // Accessors for instance variable which is not a C++ declared nonstatic
coleenp@548 86 // field.
coleenp@548 87 int length() const {
coleenp@548 88 return *(int*)(((intptr_t)this) + length_offset_in_bytes());
coleenp@548 89 }
coleenp@548 90 void set_length(int length) {
coleenp@548 91 *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;
coleenp@548 92 }
duke@435 93
coleenp@548 94 // Should only be called with constants as argument
coleenp@548 95 // (will not constant fold otherwise)
coleenp@548 96 // Returns the header size in words aligned to the requirements of the
coleenp@548 97 // array object type.
duke@435 98 static int header_size(BasicType type) {
coleenp@548 99 size_t typesize_in_bytes = header_size_in_bytes();
coleenp@548 100 return (int)(Universe::element_type_should_be_aligned(type)
kvn@1926 101 ? align_object_offset(typesize_in_bytes/HeapWordSize)
coleenp@548 102 : typesize_in_bytes/HeapWordSize);
duke@435 103 }
duke@435 104
jcoomes@916 105 // Return the maximum length of an array of BasicType. The length can passed
jcoomes@916 106 // to typeArrayOop::object_size(scale, length, header_size) without causing an
jcoomes@916 107 // overflow.
duke@435 108 static int32_t max_array_length(BasicType type) {
duke@435 109 assert(type >= 0 && type < T_CONFLICT, "wrong type");
kvn@464 110 assert(type2aelembytes(type) != 0, "wrong type");
jcoomes@916 111 const int bytes_per_element = type2aelembytes(type);
jcoomes@916 112 if (bytes_per_element < HeapWordSize) {
jcoomes@916 113 return max_jint;
jcoomes@916 114 }
jcoomes@916 115
jcoomes@916 116 const int32_t max_words = align_size_down(max_jint, MinObjAlignment);
jcoomes@916 117 const int32_t max_element_words = max_words - header_size(type);
jcoomes@916 118 const int32_t words_per_element = bytes_per_element >> LogHeapWordSize;
jcoomes@916 119 return max_element_words / words_per_element;
duke@435 120 }
duke@435 121 };
stefank@2314 122
stefank@2314 123 #endif // SHARE_VM_OOPS_ARRAYOOP_HPP

mercurial