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   switch (type) {
  39   case T_OBJECT:
  40   case T_ARRAY: {
  41     if (on_heap) {
  42       __ load_heap_oop(dst, src);
  43     } else {
  44       assert(on_root, "why else?");
  45       __ ldr(dst, src);
  46     }
  47     break;
  48   }
  49   default: Unimplemented();
  50   }
  51 }
  52 
  53 void BarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  54                                    Address dst, Register val, Register tmp1, Register tmp2) {
  55   bool on_heap = (decorators & IN_HEAP) != 0;
  56   bool on_root = (decorators & IN_ROOT) != 0;
  57   switch (type) {
  58   case T_OBJECT:
  59   case T_ARRAY: {
  60     if (on_heap) {
  61       __ store_heap_oop(dst, val);
  62     } else {
  63       assert(on_root, "why else?");
  64       __ str(val, dst);
  65     }
  66     break;
  67   }
  68   default: Unimplemented();
  69   }
  70 }
  71 
  72 void BarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
  73                                                         Register obj, Register tmp, Label& slowpath) {
  74   // If mask changes we need to ensure that the inverse is still encodable as an immediate
  75   STATIC_ASSERT(JNIHandles::weak_tag_mask == 1);
  76   __ andr(obj, obj, ~JNIHandles::weak_tag_mask);
  77   __ ldr(obj, Address(obj, 0));             // *obj
  78 }