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 "interpreter/interp_masm.hpp"
  28 #include "runtime/jniHandles.hpp"
  29 
  30 #define __ masm->
  31 
  32 void BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  33                                   Register dst, Address src, Register tmp1, Register tmp_thread) {
  34   bool on_heap = (decorators & IN_HEAP) != 0;
  35   bool on_root = (decorators & IN_ROOT) != 0;
  36   bool oop_not_null = (decorators & OOP_NOT_NULL) != 0;
  37 
  38   switch (type) {
  39   case T_OBJECT:
  40   case T_ARRAY: {
  41     if (on_heap) {
  42 #ifdef _LP64
  43       if (UseCompressedOops) {
  44         __ movl(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 #endif
  52       {
  53         __ movptr(dst, src);
  54       }
  55     } else {
  56       assert(on_root, "why else?");
  57       __ movptr(dst, src);
  58     }
  59     break;
  60   }
  61   default: Unimplemented();
  62   }
  63 }
  64 
  65 void BarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  66                                    Address dst, Register val, Register tmp1, Register tmp2) {
  67   bool on_heap = (decorators & IN_HEAP) != 0;
  68   bool on_root = (decorators & IN_ROOT) != 0;
  69   bool oop_not_null = (decorators & OOP_NOT_NULL) != 0;
  70 
  71   switch (type) {
  72   case T_OBJECT:
  73   case T_ARRAY: {
  74     if (on_heap) {
  75       if (val == noreg) {
  76         assert(!oop_not_null, "inconsistent access");
  77 #ifdef _LP64
  78         if (UseCompressedOops) {
  79           __ movl(dst, (int32_t)NULL_WORD);
  80         } else {
  81           __ movslq(dst, (int32_t)NULL_WORD);
  82         }
  83 #else
  84         __ movl(dst, (int32_t)NULL_WORD);
  85 #endif
  86       } else {
  87 #ifdef _LP64
  88         if (UseCompressedOops) {
  89           assert(!dst.uses(val), "not enough registers");
  90           if (oop_not_null) {
  91             __ encode_heap_oop_not_null(val);
  92           } else {
  93             __ encode_heap_oop(val);
  94           }
  95           __ movl(dst, val);
  96         } else
  97 #endif
  98         {
  99           __ movptr(dst, val);
 100         }
 101       }
 102     } else {
 103       assert(on_root, "why else?");
 104       assert(val != noreg, "not supported");
 105       __ movptr(dst, val);
 106     }
 107     break;
 108   }
 109   default: Unimplemented();
 110   }
 111 }
 112 
 113 void BarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
 114                                                         Register obj, Register tmp, Label& slowpath) {
 115   __ clear_jweak_tag(obj);
 116   __ movptr(obj, Address(obj, 0));
 117 }