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 
  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   bool on_heap = (decorators & IN_HEAP) != 0;
  34   bool on_root = (decorators & IN_ROOT) != 0;
  35   bool oop_not_null = (decorators & OOP_NOT_NULL) != 0;
  36 
  37   switch (type) {
  38   case T_OBJECT:
  39   case T_ARRAY: {
  40     if (on_heap) {
  41 #ifdef _LP64
  42       if (UseCompressedOops) {
  43         __ movl(dst, src);
  44         if (oop_not_null) {
  45           __ decode_heap_oop_not_null(dst);
  46         } else {
  47           __ decode_heap_oop(dst);
  48         }
  49       } else
  50 #endif
  51       {
  52         __ movptr(dst, src);
  53       }
  54     } else {
  55       assert(on_root, "why else?");
  56       __ movptr(dst, src);
  57     }
  58     break;
  59   }
  60   default: Unimplemented();
  61   }
  62 }
  63 
  64 void BarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  65                                    Address dst, Register val, Register tmp1, Register tmp2) {
  66   bool on_heap = (decorators & IN_HEAP) != 0;
  67   bool on_root = (decorators & IN_ROOT) != 0;
  68   bool oop_not_null = (decorators & OOP_NOT_NULL) != 0;
  69 
  70   switch (type) {
  71   case T_OBJECT:
  72   case T_ARRAY: {
  73     if (on_heap) {
  74       if (val == noreg) {
  75         assert(!oop_not_null, "inconsistent access");
  76 #ifdef _LP64
  77         if (UseCompressedOops) {
  78           __ movl(dst, (int32_t)NULL_WORD);
  79         } else {
  80           __ movslq(dst, (int32_t)NULL_WORD);
  81         }
  82 #else
  83         __ movl(dst, (int32_t)NULL_WORD);
  84 #endif
  85       } else {
  86 #ifdef _LP64
  87         if (UseCompressedOops) {
  88           assert(!dst.uses(val), "not enough registers");
  89           if (oop_not_null) {
  90             __ encode_heap_oop_not_null(val);
  91           } else {
  92             __ encode_heap_oop(val);
  93           }
  94           __ movl(dst, val);
  95         } else
  96 #endif
  97         {
  98           __ movptr(dst, val);
  99         }
 100       }
 101     } else {
 102       assert(on_root, "why else?");
 103       assert(val != noreg, "not supported");
 104       __ movptr(dst, val);
 105     }
 106     break;
 107   }
 108   default: Unimplemented();
 109   }
 110 }
 111 
 112 void BarrierSetAssembler::obj_equals(MacroAssembler* masm, DecoratorSet decorators, Register src1, Register src2) {
 113   __ cmpptr(src1, src2);
 114 }
 115 
 116 void BarrierSetAssembler::obj_equals_addr(MacroAssembler* masm, DecoratorSet decorators, Register src1, Address src2) {
 117   __ cmpptr(src1, src2);
 118 }
 119 
 120 void BarrierSetAssembler::resolve_for_read(MacroAssembler* masm, DecoratorSet decorators, Register obj) {
 121   // Default to no-op
 122 }
 123 
 124 void BarrierSetAssembler::resolve_for_write(MacroAssembler* masm, DecoratorSet decorators, Register obj) {
 125   // Default to no-op
 126 }