1 /*
   2  * Copyright (c) 2016, 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 "gc/shared/barrierSetCodeGen.hpp"
  26 #include "interpreter/interp_masm.hpp"
  27 
  28 #define __ masm->
  29 
  30 void BarrierSetCodeGen::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  31                                  Register base, Register index, int offset, Register val, Register tmp) {
  32   bool on_heap = (decorators & ACCESS_ON_HEAP) != 0;
  33   bool on_root = (decorators & ACCESS_ON_ROOT) != 0;
  34 
  35   switch (type) {
  36   case T_ARRAY:
  37   case T_OBJECT: {
  38     if (on_heap) {
  39       if (index == noreg ) {
  40         if (Assembler::is_simm13(offset)) {
  41           __ store_heap_oop(val, base, offset);
  42         } else {
  43           __ set(offset, tmp);
  44           __ store_heap_oop(val, base, tmp);
  45         }
  46       } else {
  47         assert(offset == 0, "not implemented yet");
  48         __ store_heap_oop(val, base, index);
  49       }
  50     } else {
  51       assert(on_root, "why else?");
  52       assert(Assembler::is_simm13(offset), "not supported yet");
  53       assert(index == noreg, "not supported yet");
  54       __ st_ptr(val, base, offset);
  55     }
  56     break;
  57   }
  58   default: Unimplemented();
  59   }
  60 }
  61 
  62 void BarrierSetCodeGen::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
  63                                 Register base, Register index, int offset, Register dst, Register tmp) {
  64   bool on_heap = (decorators & ACCESS_ON_HEAP) != 0;
  65   bool on_root = (decorators & ACCESS_ON_ROOT) != 0;
  66 
  67   switch (type) {
  68   case T_ARRAY:
  69   case T_OBJECT: {
  70     if (on_heap) {
  71       if (index == noreg ) {
  72         if (Assembler::is_simm13(offset)) {
  73           __ load_heap_oop(base, offset, dst);
  74         } else {
  75           __ set(offset, tmp);
  76           __ load_heap_oop(base, tmp, dst);
  77         }
  78       } else {
  79         assert(offset == 0, "not implemented yet");
  80         __ load_heap_oop(base, index, dst);
  81       }
  82     } else {
  83       assert(on_root, "why else?");
  84       assert(Assembler::is_simm13(offset), "not supported yet");
  85       assert(index == noreg, "not supported yet");
  86       __ ld_ptr(base, offset, dst);
  87     }
  88     break;
  89   }
  90   default: Unimplemented();
  91   }
  92 }