hotspot/src/share/vm/oops/objArrayOop.hpp
author stefank
Fri, 13 Feb 2015 14:37:35 +0100
changeset 29081 c61eb4914428
parent 27427 5c3f72c4c703
child 29688 2a0cad173059
permissions -rw-r--r--
8072911: Remove includes of oop.inline.hpp from .hpp files Reviewed-by: brutisso, coleenp, jwilhelm, simonis, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27427
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 4465
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4465
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: 4465
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
#ifndef SHARE_VM_OOPS_OBJARRAYOOP_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_OOPS_OBJARRAYOOP_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "oops/arrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// An objArrayOop is an array containing oops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Evaluating "String arg[10]" will create an objArrayOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class objArrayOopDesc : public arrayOopDesc {
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 11176
diff changeset
    34
  friend class ObjArrayKlass;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    35
  friend class Runtime1;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    36
  friend class psPromotionManager;
11176
9bb1ddd8da51 7112743: G1: Reduce overhead of marking closure during evacuation pauses
johnc
parents: 7397
diff changeset
    37
  friend class CSetMarkOopClosure;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
    38
  friend class G1ParScanPartialArrayClosure;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    39
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    40
  template <class T> T* obj_at_addr(int index) const {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    41
    assert(is_within_bounds(index), "index out of bounds");
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    42
    return &((T*)base())[index];
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    43
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    44
4461
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    45
private:
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    46
  // Give size of objArrayOop in HeapWords minus the header
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    47
  static int array_size(int length) {
27427
5c3f72c4c703 8054530: C2: assert(res == old_res) failed: Inconsistency between old and new
morris
parents: 25325
diff changeset
    48
    const uint OopsPerHeapWord = HeapWordSize/heapOopSize;
4461
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    49
    assert(OopsPerHeapWord >= 1 && (HeapWordSize % heapOopSize == 0),
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    50
           "Else the following (new) computation would be in error");
27427
5c3f72c4c703 8054530: C2: assert(res == old_res) failed: Inconsistency between old and new
morris
parents: 25325
diff changeset
    51
    uint res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
4461
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    52
#ifdef ASSERT
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    53
    // The old code is left in for sanity-checking; it'll
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    54
    // go away pretty soon. XXX
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    55
    // Without UseCompressedOops, this is simply:
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    56
    // oop->length() * HeapWordsPerOop;
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    57
    // With narrowOops, HeapWordsPerOop is 1/2 or equal 0 as an integer.
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    58
    // The oop elements are aligned up to wordSize
27427
5c3f72c4c703 8054530: C2: assert(res == old_res) failed: Inconsistency between old and new
morris
parents: 25325
diff changeset
    59
    const uint HeapWordsPerOop = heapOopSize/HeapWordSize;
5c3f72c4c703 8054530: C2: assert(res == old_res) failed: Inconsistency between old and new
morris
parents: 25325
diff changeset
    60
    uint old_res;
4461
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    61
    if (HeapWordsPerOop > 0) {
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    62
      old_res = length * HeapWordsPerOop;
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    63
    } else {
27427
5c3f72c4c703 8054530: C2: assert(res == old_res) failed: Inconsistency between old and new
morris
parents: 25325
diff changeset
    64
      old_res = align_size_up((uint)length, OopsPerHeapWord)/OopsPerHeapWord;
4461
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    65
    }
27427
5c3f72c4c703 8054530: C2: assert(res == old_res) failed: Inconsistency between old and new
morris
parents: 25325
diff changeset
    66
    assert(res == old_res, "Inconsistency between old and new.");
4461
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    67
#endif  // ASSERT
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    68
    return res;
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    69
  }
c17c526d36ef 6906727: UseCompressedOops: some card-marking fixes related to object arrays
ysr
parents: 3795
diff changeset
    70
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
 public:
3595
d67c151b72a5 6860920: serialize.cpp shouldn't use objArrayOopDesc::base_offset_in_bytes(T_BYTE)
twisti
parents: 1388
diff changeset
    72
  // Returns the offset of the first element.
d67c151b72a5 6860920: serialize.cpp shouldn't use objArrayOopDesc::base_offset_in_bytes(T_BYTE)
twisti
parents: 1388
diff changeset
    73
  static int base_offset_in_bytes() {
d67c151b72a5 6860920: serialize.cpp shouldn't use objArrayOopDesc::base_offset_in_bytes(T_BYTE)
twisti
parents: 1388
diff changeset
    74
    return arrayOopDesc::base_offset_in_bytes(T_OBJECT);
d67c151b72a5 6860920: serialize.cpp shouldn't use objArrayOopDesc::base_offset_in_bytes(T_BYTE)
twisti
parents: 1388
diff changeset
    75
  }
d67c151b72a5 6860920: serialize.cpp shouldn't use objArrayOopDesc::base_offset_in_bytes(T_BYTE)
twisti
parents: 1388
diff changeset
    76
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    77
  // base is the address following the header.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    78
  HeapWord* base() const      { return (HeapWord*) arrayOopDesc::base(T_OBJECT); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    79
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Accessing
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27427
diff changeset
    81
  oop obj_at(int index) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    83
  void obj_at_put(int index, oop value) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    84
    if (UseCompressedOops) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    85
      oop_store(obj_at_addr<narrowOop>(index), value);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    86
    } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    87
      oop_store(obj_at_addr<oop>(index), value);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    88
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    89
  }
25325
e3af4e02b0d5 8026977: NPG: Remove ConstantPool::lock
coleenp
parents: 13963
diff changeset
    90
e3af4e02b0d5 8026977: NPG: Remove ConstantPool::lock
coleenp
parents: 13963
diff changeset
    91
  oop atomic_compare_exchange_oop(int index, oop exchange_value, oop compare_value);
e3af4e02b0d5 8026977: NPG: Remove ConstantPool::lock
coleenp
parents: 13963
diff changeset
    92
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Sizing
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    94
  static int header_size()    { return arrayOopDesc::header_size(T_OBJECT); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    95
  int object_size()           { return object_size(length()); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    96
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    97
  static int object_size(int length) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    98
    // This returns the object size in HeapWords.
4465
7b73e0380188 6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727
ysr
parents: 4461
diff changeset
    99
    uint asz = array_size(length);
7b73e0380188 6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727
ysr
parents: 4461
diff changeset
   100
    uint osz = align_object_size(header_size() + asz);
7b73e0380188 6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727
ysr
parents: 4461
diff changeset
   101
    assert(osz >= asz,   "no overflow");
7b73e0380188 6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727
ysr
parents: 4461
diff changeset
   102
    assert((int)osz > 0, "no overflow");
7b73e0380188 6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727
ysr
parents: 4461
diff changeset
   103
    return (int)osz;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   104
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   106
  // special iterators for index ranges, returns size of object
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   107
#define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix)     \
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   108
  int oop_iterate_range(OopClosureType* blk, int start, int end);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   109
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   110
  ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayOop_OOP_ITERATE_DECL)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   111
  ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayOop_OOP_ITERATE_DECL)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   113
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   114
#endif // SHARE_VM_OOPS_OBJARRAYOOP_HPP