src/hotspot/share/oops/compressedOops.inline.hpp
author lfoltan
Mon, 25 Jun 2018 11:33:11 -0400
changeset 50761 cb07f4b539fc
parent 49592 77fb0be7d19f
child 52107 0c1e44da019c
permissions -rw-r--r--
8169559: Add class loader names to relevant VM messages Summary: Added new method class_in_module_of_loader to provide a standard format for class information within error messages. Reviewed-by: goetz, hseigel, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     1
/*
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     4
 *
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     8
 *
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    13
 * accompanied this code).
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    14
 *
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    18
 *
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    21
 * questions.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    22
 *
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    23
 */
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    24
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    25
#ifndef SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    26
#define SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    27
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    29
#include "memory/universe.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    30
#include "oops/oop.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    31
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    32
// Functions for encoding and decoding compressed oops.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    33
// If the oops are compressed, the type passed to these overloaded functions
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    34
// is narrowOop.  All functions are overloaded so they can be called by
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    35
// template functions without conditionals (the compiler instantiates via
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    36
// the right type and inlines the appropriate code).
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    37
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    38
// Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    39
// offset from the heap base.  Saving the check for null can save instructions
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    40
// in inner GC loops so these are separated.
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    41
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    42
namespace CompressedOops {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    43
  inline bool is_null(oop obj)       { return obj == NULL; }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    44
  inline bool is_null(narrowOop obj) { return obj == 0; }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    45
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    46
  inline oop decode_not_null(narrowOop v) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    47
    assert(!is_null(v), "narrow oop value can never be zero");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    48
    address base = Universe::narrow_oop_base();
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    49
    int    shift = Universe::narrow_oop_shift();
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    50
    oop result = (oop)(void*)((uintptr_t)base + ((uintptr_t)v << shift));
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    51
    assert(check_obj_alignment(result), "address not aligned: " INTPTR_FORMAT, p2i((void*) result));
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    52
    return result;
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    53
  }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    54
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    55
  inline oop decode(narrowOop v) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    56
    return is_null(v) ? (oop)NULL : decode_not_null(v);
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    57
  }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    58
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    59
  inline narrowOop encode_not_null(oop v) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    60
    assert(!is_null(v), "oop value can never be zero");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    61
    assert(check_obj_alignment(v), "Address not aligned");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    62
    assert(Universe::heap()->is_in_reserved(v), "Address not in heap");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    63
    address base = Universe::narrow_oop_base();
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    64
    int    shift = Universe::narrow_oop_shift();
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    65
    uint64_t  pd = (uint64_t)(pointer_delta((void*)v, (void*)base, 1));
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    66
    assert(OopEncodingHeapMax > pd, "change encoding max if new encoding");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    67
    uint64_t result = pd >> shift;
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    68
    assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    69
    assert(decode(result) == v, "reversibility");
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    70
    return (narrowOop)result;
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    71
  }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    72
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    73
  inline narrowOop encode(oop v) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    74
    return is_null(v) ? (narrowOop)0 : encode_not_null(v);
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    75
  }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    76
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    77
  // No conversions needed for these overloads
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    78
  inline oop decode_not_null(oop v)             { return v; }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    79
  inline oop decode(oop v)                      { return v; }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    80
  inline narrowOop encode_not_null(narrowOop v) { return v; }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    81
  inline narrowOop encode(narrowOop v)          { return v; }
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    82
}
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    83
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff changeset
    84
#endif // SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP