| 1 | /* |
| 2 | * Copyright (c) 2016, 2017, 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/sharedRuntime.hpp" |
| 28 | #include "vmreg_x86.inline.hpp" |
| 29 | #ifdef COMPILER1 |
| 30 | #include "c1/c1_Runtime1.hpp" |
| 31 | #endif //COMPILER1 |
| 32 | |
| 33 | #define __ masm-> |
| 34 | |
| 35 | #ifdef COMPILER1 |
| 36 | // --------------------------------------------------------------------------- |
| 37 | // Object.hashCode, System.identityHashCode can pull the hashCode from the |
| 38 | // header word instead of doing a full VM transition once it's been computed. |
| 39 | // Since hashCode is usually polymorphic at call sites we can't do this |
| 40 | // optimization at the call site without a lot of work. |
| 41 | void SharedRuntime::inline_check_hashcode_from_object_header(MacroAssembler* masm, |
| 42 | const methodHandle& method, |
| 43 | Register obj_reg, |
| 44 | Register result) { |
| 45 | Label slowCase; |
| 46 | |
| 47 | // Unlike for Object.hashCode, System.identityHashCode is static method and |
| 48 | // gets object as argument instead of the receiver. |
| 49 | if (method->intrinsic_id() == vmIntrinsics::_identityHashCode) { |
| 50 | Label Continue; |
| 51 | // return 0 for null reference input |
| 52 | __ cmpptr(obj_reg, (int32_t)NULL_WORD); |
| 53 | __ jcc(Assembler::notEqual, Continue); |
| 54 | __ xorptr(result, result); |
| 55 | __ ret(0); |
| 56 | __ bind(Continue); |
| 57 | } |
| 58 | |
| 59 | __ movptr(result, Address(obj_reg, oopDesc::mark_offset_in_bytes())); |
| 60 | |
| 61 | // check if locked |
| 62 | __ testptr(result, markOopDesc::unlocked_value); |
| 63 | __ jcc(Assembler::zero, slowCase); |
| 64 | |
| 65 | if (UseBiasedLocking) { |
| 66 | // Check if biased and fall through to runtime if so |
| 67 | __ testptr(result, markOopDesc::biased_lock_bit_in_place); |
| 68 | __ jcc(Assembler::notZero, slowCase); |
| 69 | } |
| 70 | |
| 71 | // get hash |
| 72 | #ifdef _LP64 |
| 73 | // Read the header and build a mask to get its hash field. |
| 74 | // Depend on hash_mask being at most 32 bits and avoid the use of hash_mask_in_place |
| 75 | // because it could be larger than 32 bits in a 64-bit vm. See markOop.hpp. |
| 76 | __ shrptr(result, markOopDesc::hash_shift); |
| 77 | __ andptr(result, markOopDesc::hash_mask); |
| 78 | #else |
| 79 | __ andptr(result, markOopDesc::hash_mask_in_place); |
| 80 | #endif //_LP64 |
| 81 | |
| 82 | // test if hashCode exists |
| 83 | __ jcc(Assembler::zero, slowCase); |
| 84 | #ifndef _LP64 |
| 85 | __ shrptr(result, markOopDesc::hash_shift); |
| 86 | #endif |
| 87 | __ ret(0); |
| 88 | __ bind(slowCase); |
| 89 | } |
| 90 | #endif //COMPILER1 |
| 91 | |
| 92 | |