1 /*
  2  * Copyright (c) 2016, 2021, 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/macroAssembler.hpp"
 27 #include "runtime/interfaceSupport.inline.hpp"
 28 #include "runtime/sharedRuntime.hpp"
 29 #include "vmreg_x86.inline.hpp"
 30 #ifdef COMPILER1
 31 #include "c1/c1_Runtime1.hpp"
 32 #endif //COMPILER1
 33 
 34 #define __ masm->
 35 
 36 #ifdef COMPILER1
 37 // ---------------------------------------------------------------------------
 38 // Object.hashCode, System.identityHashCode can pull the hashCode from the
 39 // header word instead of doing a full VM transition once it's been computed.
 40 // Since hashCode is usually polymorphic at call sites we can't do this
 41 // optimization at the call site without a lot of work.
 42 void SharedRuntime::inline_check_hashcode_from_object_header(MacroAssembler* masm,
 43                                  const methodHandle& method,
 44                                  Register obj_reg,
 45                                  Register result) {
 46   Label slowCase;
 47 
 48   // Unlike for Object.hashCode, System.identityHashCode is static method and
 49   // gets object as argument instead of the receiver.
 50   if (method->intrinsic_id() == vmIntrinsics::_identityHashCode) {
 51     Label Continue;
 52     // return 0 for null reference input
 53     __ cmpptr(obj_reg, NULL_WORD);
 54     __ jcc(Assembler::notEqual, Continue);
 55     __ xorptr(result, result);
 56     __ ret(0);
 57     __ bind(Continue);
 58   }
 59 
 60   __ movptr(result, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
 61 
 62   // check if locked
 63   __ testptr(result, markWord::unlocked_value);
 64   __ jcc(Assembler::zero, slowCase);
 65 
 66   // get hash
 67 #ifdef _LP64
 68   // Read the header and build a mask to get its hash field.
 69   // Depend on hash_mask being at most 32 bits and avoid the use of hash_mask_in_place
 70   // because it could be larger than 32 bits in a 64-bit vm. See markWord.hpp.
 71   if (UseCompactObjectHeaders) {
 72     __ shrptr(result, markWord::hash_shift_compact);
 73     __ andptr(result, markWord::hash_mask_compact);
 74   } else {
 75     __ shrptr(result, markWord::hash_shift);
 76     __ andptr(result, markWord::hash_mask);
 77   }
 78 #else
 79   __ andptr(result, markWord::hash_mask_in_place);
 80 #endif //_LP64
 81 
 82   // test if hashCode exists
 83   __ jcc(Assembler::zero, slowCase);
 84 #ifndef _LP64
 85   __ shrptr(result, markWord::hash_shift);
 86 #endif
 87   __ ret(0);
 88   __ bind(slowCase);
 89 }
 90 #endif //COMPILER1
 91 
 92 #if defined(TARGET_COMPILER_gcc) && !defined(_WIN64)
 93 JRT_LEAF(jfloat, SharedRuntime::frem(jfloat x, jfloat y))
 94   jfloat retval;
 95   asm ("\
 96 1:               \n\
 97 fprem            \n\
 98 fnstsw %%ax      \n\
 99 test   $0x4,%%ah \n\
100 jne    1b        \n\
101 "
102     :"=t"(retval)
103     :"0"(x), "u"(y)
104     :"cc", "ax");
105   return retval;
106 JRT_END
107 
108 JRT_LEAF(jdouble, SharedRuntime::drem(jdouble x, jdouble y))
109   jdouble retval;
110   asm ("\
111 1:               \n\
112 fprem            \n\
113 fnstsw %%ax      \n\
114 test   $0x4,%%ah \n\
115 jne    1b        \n\
116 "
117     :"=t"(retval)
118     :"0"(x), "u"(y)
119     :"cc", "ax");
120   return retval;
121 JRT_END
122 #endif // TARGET_COMPILER_gcc && !_WIN64