< prev index next >

src/hotspot/share/oops/compressedOops.inline.hpp

Print this page


   1 /*
   2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
  26 #define SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "memory/universe.hpp"
  30 #include "oops/compressedOops.hpp"
  31 #include "oops/oop.hpp"

  32 
  33 // Functions for encoding and decoding compressed oops.
  34 // If the oops are compressed, the type passed to these overloaded functions
  35 // is narrowOop.  All functions are overloaded so they can be called by
  36 // template functions without conditionals (the compiler instantiates via
  37 // the right type and inlines the appropriate code).
  38 
  39 // Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit
  40 // offset from the heap base.  Saving the check for null can save instructions
  41 // in inner GC loops so these are separated.
  42 
  43 inline oop CompressedOops::decode_raw(narrowOop v) {
  44   return (oop)(void*)((uintptr_t)base() + ((uintptr_t)v << shift()));
  45 }
  46 
  47 inline oop CompressedOops::decode_not_null(narrowOop v) {
  48   assert(!is_null(v), "narrow oop value can never be zero");
  49   oop result = decode_raw(v);
  50   assert(check_obj_alignment(result), "address not aligned: " INTPTR_FORMAT, p2i((void*) result));
  51   return result;
  52 }
  53 
  54 inline oop CompressedOops::decode(narrowOop v) {
  55   return is_null(v) ? (oop)NULL : decode_not_null(v);
  56 }
  57 
  58 inline narrowOop CompressedOops::encode_not_null(oop v) {
  59   assert(!is_null(v), "oop value can never be zero");
  60   DEBUG_ONLY(Universe::heap()->check_oop_location(v);)
  61   uint64_t  pd = (uint64_t)(pointer_delta((void*)v, (void*)base(), 1));
  62   assert(OopEncodingHeapMax > pd, "change encoding max if new encoding");
  63   uint64_t result = pd >> shift();
  64   assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow");
  65   assert(decode(result) == v, "reversibility");
  66   return (narrowOop)result;
  67 }
  68 
  69 inline narrowOop CompressedOops::encode(oop v) {
  70   return is_null(v) ? (narrowOop)0 : encode_not_null(v);


   1 /*
   2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
  26 #define SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "memory/universe.hpp"
  30 #include "oops/compressedOops.hpp"
  31 #include "oops/oop.hpp"
  32 #include "utilities/align.hpp"
  33 
  34 // Functions for encoding and decoding compressed oops.
  35 // If the oops are compressed, the type passed to these overloaded functions
  36 // is narrowOop.  All functions are overloaded so they can be called by
  37 // template functions without conditionals (the compiler instantiates via
  38 // the right type and inlines the appropriate code).
  39 
  40 // Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit
  41 // offset from the heap base.  Saving the check for null can save instructions
  42 // in inner GC loops so these are separated.
  43 
  44 inline oop CompressedOops::decode_raw(narrowOop v) {
  45   return (oop)(void*)((uintptr_t)base() + ((uintptr_t)v << shift()));
  46 }
  47 
  48 inline oop CompressedOops::decode_not_null(narrowOop v) {
  49   assert(!is_null(v), "narrow oop value can never be zero");
  50   oop result = decode_raw(v);
  51   assert(is_object_aligned(result), "address not aligned: " INTPTR_FORMAT, p2i((void*) result));
  52   return result;
  53 }
  54 
  55 inline oop CompressedOops::decode(narrowOop v) {
  56   return is_null(v) ? (oop)NULL : decode_not_null(v);
  57 }
  58 
  59 inline narrowOop CompressedOops::encode_not_null(oop v) {
  60   assert(!is_null(v), "oop value can never be zero");
  61   DEBUG_ONLY(Universe::heap()->check_oop_location(v);)
  62   uint64_t  pd = (uint64_t)(pointer_delta((void*)v, (void*)base(), 1));
  63   assert(OopEncodingHeapMax > pd, "change encoding max if new encoding");
  64   uint64_t result = pd >> shift();
  65   assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow");
  66   assert(decode(result) == v, "reversibility");
  67   return (narrowOop)result;
  68 }
  69 
  70 inline narrowOop CompressedOops::encode(oop v) {
  71   return is_null(v) ? (narrowOop)0 : encode_not_null(v);


< prev index next >