1 /*
   2  * Copyright (c) 1997, 2017, 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 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "oops/instanceRefKlass.inline.hpp"
  29 #include "oops/oop.inline.hpp"
  30 
  31 void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) {
  32   // Clear the nonstatic oop-map entries corresponding to referent
  33   // and nextPending field.  They are treated specially by the
  34   // garbage collector.
  35   // The discovered field is used only by the garbage collector
  36   // and is also treated specially.
  37   InstanceKlass* ik = InstanceKlass::cast(k);
  38 
  39   // Check that we have the right class
  40   debug_only(static bool first_time = true);
  41   assert(k == SystemDictionary::Reference_klass() && first_time,
  42          "Invalid update of maps");
  43   debug_only(first_time = false);
  44   assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  45 
  46   OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  47 
  48   // Check that the current map is (2,4) - currently points at field with
  49   // offset 2 (words) and has 4 map entries.
  50   debug_only(int offset = java_lang_ref_Reference::referent_offset);
  51   debug_only(unsigned int count = ((java_lang_ref_Reference::discovered_offset -
  52     java_lang_ref_Reference::referent_offset)/heapOopSize) + 1);
  53 
  54   if (UseSharedSpaces) {
  55     assert(map->offset() == java_lang_ref_Reference::queue_offset &&
  56            map->count() == 1, "just checking");
  57   } else {
  58     assert(map->offset() == offset && map->count() == count,
  59            "just checking");
  60 
  61     // Update map to (3,1) - point to offset of 3 (words) with 1 map entry.
  62     map->set_offset(java_lang_ref_Reference::queue_offset);
  63     map->set_count(1);
  64   }
  65 }
  66 
  67 
  68 // Verification
  69 
  70 void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
  71   InstanceKlass::oop_verify_on(obj, st);
  72   // Verify referent field
  73   oop referent = java_lang_ref_Reference::referent(obj);
  74   if (referent != NULL) {
  75     guarantee(oopDesc::is_oop(referent), "referent field heap failed");
  76   }
  77   // Verify next field
  78   oop next = java_lang_ref_Reference::next(obj);
  79   if (next != NULL) {
  80     guarantee(oopDesc::is_oop(next), "next field should be an oop");
  81     guarantee(next->is_instance(), "next field should be an instance");
  82     guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");
  83   }
  84 }