1 /*
   2  * Copyright (c) 2008, 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 "asm/assembler.hpp"
  27 #include "asm/assembler.inline.hpp"
  28 #include "ci/ciEnv.hpp"
  29 #include "gc/shared/cardTableBarrierSet.hpp"
  30 #include "gc/shared/collectedHeap.inline.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "interpreter/templateInterpreterGenerator.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "prims/jvm_misc.hpp"
  36 #include "prims/methodHandles.hpp"
  37 #include "runtime/biasedLocking.hpp"
  38 #include "runtime/interfaceSupport.inline.hpp"
  39 #include "runtime/objectMonitor.hpp"
  40 #include "runtime/os.hpp"
  41 #include "runtime/sharedRuntime.hpp"
  42 #include "runtime/stubRoutines.hpp"
  43 #include "utilities/hashtable.hpp"
  44 #include "utilities/macros.hpp"
  45 
  46 #ifdef COMPILER2
  47 // Convert the raw encoding form into the form expected by the
  48 // constructor for Address.
  49 Address Address::make_raw(int base, int index, int scale, int disp, relocInfo::relocType disp_reloc) {
  50   RelocationHolder rspec;
  51   if (disp_reloc != relocInfo::none) {
  52     rspec = Relocation::spec_simple(disp_reloc);
  53   }
  54 
  55   Register rindex = as_Register(index);
  56   if (rindex != PC) {
  57     assert(disp == 0, "unsupported");
  58     Address madr(as_Register(base), rindex, lsl, scale);
  59     madr._rspec = rspec;
  60     return madr;
  61   } else {
  62     assert(scale == 0, "not supported");
  63     Address madr(as_Register(base), disp);
  64     madr._rspec = rspec;
  65     return madr;
  66   }
  67 }
  68 #endif
  69 
  70 void AsmOperand::initialize_rotated_imm(unsigned int imm) {
  71   for (int shift = 2; shift <= 24; shift += 2) {
  72     if ((imm & ~(0xff << shift)) == 0) {
  73       _encoding = 1 << 25 | (32 - shift) << 7 | imm >> shift;
  74       return;
  75     }
  76   }
  77   assert((imm & 0x0ffffff0) == 0, "too complicated constant: %d (%x)", imm, imm);
  78   _encoding = 1 << 25 | 4 << 7 | imm >> 28 | imm << 4;
  79 }
  80 
  81 bool AsmOperand::is_rotated_imm(unsigned int imm) {
  82   if ((imm >> 8) == 0) {
  83     return true;
  84   }
  85   for (int shift = 2; shift <= 24; shift += 2) {
  86     if ((imm & ~(0xff << shift)) == 0) {
  87       return true;
  88     }
  89   }
  90   if ((imm & 0x0ffffff0) == 0) {
  91     return true;
  92   }
  93   return false;
  94 }