1 /*
   2  * Copyright (c) 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 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSetAssembler.hpp"
  27 #include "runtime/jniHandles.hpp"
  28 
  29 #define __ masm->
  30 
  31 void BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  32                                   Register dst, Address src, Register tmp1, Register tmp_thread) {
  33 
  34   // LR is live.  It must be saved around calls.
  35 
  36   bool on_heap = (decorators & IN_HEAP) != 0;
  37   bool on_root = (decorators & IN_ROOT) != 0;
  38   bool oop_not_null = (decorators & OOP_NOT_NULL) != 0;
  39   switch (type) {
  40   case T_OBJECT:
  41   case T_ARRAY: {
  42     if (on_heap) {
  43       if (UseCompressedOops) {
  44         __ ldrw(dst, src);
  45         if (oop_not_null) {
  46           __ decode_heap_oop_not_null(dst);
  47         } else {
  48           __ decode_heap_oop(dst);
  49         }
  50       } else {
  51         __ ldr(dst, src);
  52       }
  53     } else {
  54       assert(on_root, "why else?");
  55       __ ldr(dst, src);
  56     }
  57     break;
  58   }
  59   default: Unimplemented();
  60   }
  61 }
  62 
  63 void BarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  64                                    Address dst, Register val, Register tmp1, Register tmp2) {
  65   bool on_heap = (decorators & IN_HEAP) != 0;
  66   bool on_root = (decorators & IN_ROOT) != 0;
  67   switch (type) {
  68   case T_OBJECT:
  69   case T_ARRAY: {
  70     val = val == noreg ? zr : val;
  71     if (on_heap) {
  72       if (UseCompressedOops) {
  73         assert(!dst.uses(val), "not enough registers");
  74         if (val != zr) {
  75           __ encode_heap_oop(val);
  76         }
  77         __ strw(val, dst);
  78       } else {
  79         __ str(val, dst);
  80       }
  81     } else {
  82       assert(on_root, "why else?");
  83       __ str(val, dst);
  84     }
  85     break;
  86   }
  87   default: Unimplemented();
  88   }
  89 }
  90 
  91 void BarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
  92                                                         Register obj, Register tmp, Label& slowpath) {
  93   // If mask changes we need to ensure that the inverse is still encodable as an immediate
  94   STATIC_ASSERT(JNIHandles::weak_tag_mask == 1);
  95   __ andr(obj, obj, ~JNIHandles::weak_tag_mask);
  96   __ ldr(obj, Address(obj, 0));             // *obj
  97 }