view src/share/vm/oops/klass.inline.hpp @ 5093:740e263c80c6

8003424: Enable Class Data Sharing for CompressedOops 8016729: ObjectAlignmentInBytes=16 now forces the use of heap based compressed oops 8005933: The -Xshare:auto option is ignored for -server Summary: Move klass metaspace above the heap and support CDS with compressed klass ptrs. Reviewed-by: coleenp, kvn, mgerdin, tschatzl, stefank
author hseigel
date Thu, 15 Aug 2013 20:04:10 -0400
parents f95d63e2154a
children 53a41e7cbe05
line wrap: on
line source
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit if you need additional information or have any
 * questions.


#include "memory/universe.hpp"
#include "oops/klass.hpp"
#include "oops/markOop.hpp"

inline void Klass::set_prototype_header(markOop header) {
  assert(!header->has_bias_pattern() || oop_is_instance(), "biased locking currently only supported for Java instances");
  _prototype_header = header;

inline bool Klass::is_null(Klass* obj)  { return obj == NULL; }
inline bool Klass::is_null(narrowKlass obj) { return obj == 0; }

// Encoding and decoding for klass field.

inline bool check_klass_alignment(Klass* obj) {
  return (intptr_t)obj % KlassAlignmentInBytes == 0;

inline narrowKlass Klass::encode_klass_not_null(Klass* v) {
  assert(!is_null(v), "klass value can never be zero");
  assert(check_klass_alignment(v), "Address not aligned");
  int    shift = Universe::narrow_klass_shift();
  uint64_t pd = (uint64_t)(pointer_delta((void*)v, Universe::narrow_klass_base(), 1));
  assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding");
  uint64_t result = pd >> shift;
  assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow");
  assert(decode_klass(result) == v, "reversibility");
  return (narrowKlass)result;

inline narrowKlass Klass::encode_klass(Klass* v) {
  return is_null(v) ? (narrowKlass)0 : encode_klass_not_null(v);

inline Klass* Klass::decode_klass_not_null(narrowKlass v) {
  assert(!is_null(v), "narrow klass value can never be zero");
  int    shift = Universe::narrow_klass_shift();
  Klass* result = (Klass*)(void*)((uintptr_t)Universe::narrow_klass_base() + ((uintptr_t)v << shift));
  assert(check_klass_alignment(result), err_msg("address not aligned: " PTR_FORMAT, (void*) result));
  return result;

inline Klass* Klass::decode_klass(narrowKlass v) {
  return is_null(v) ? (Klass*)NULL : decode_klass_not_null(v);