1 /*
   2  * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc_implementation/shenandoah/shenandoahBarrierSet.hpp"
  26 #include "gc_implementation/shenandoah/shenandoahBarrierSetC2.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahRuntime.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahSupport.hpp"
  29 #include "opto/type.hpp"
  30 #include "runtime/thread.hpp"
  31 
  32 ShenandoahBarrierSetC2* ShenandoahBarrierSetC2::bsc2() {
  33   return ShenandoahBarrierSet::barrier_set()->bsc2();
  34 }
  35 
  36 bool ShenandoahBarrierSetC2::is_shenandoah_lrb_call(Node* call) {
  37   return call->is_CallLeaf() &&
  38          call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_JRT);
  39 }
  40 
  41 bool ShenandoahBarrierSetC2::is_shenandoah_state_load(Node* n) {
  42   if (!n->is_Load()) return false;
  43   const int state_offset = in_bytes(JavaThread::gc_state_offset());
  44   return n->in(2)->is_AddP() && n->in(2)->in(2)->Opcode() == Op_ThreadLocal
  45          && n->in(2)->in(3)->is_Con()
  46          && n->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == state_offset;
  47 }
  48 
  49 const TypeFunc* ShenandoahBarrierSetC2::shenandoah_load_reference_barrier_Type() {
  50   const Type **fields = TypeTuple::fields(1);
  51   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
  52   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
  53 
  54   // create result type (range)
  55   fields = TypeTuple::fields(1);
  56   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
  57   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
  58 
  59   return TypeFunc::make(domain, range);
  60 }
  61 
  62 Node* ShenandoahBarrierSetC2::step_over_gc_barrier(Node* c) {
  63   if (c->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
  64     return c->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
  65   }
  66   return c;
  67 }
  68 
  69 Node* ShenandoahBarrierSetC2::load_reference_barrier(GraphKit* kit, Node* n) const {
  70   if (ShenandoahLoadRefBarrier) {
  71     return kit->gvn().transform(new (kit->C) ShenandoahLoadReferenceBarrierNode(NULL, n));
  72   } else {
  73     return n;
  74   }
  75 }