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 #ifndef SHARE_VM_COMPILER_CODECACHE_INLINE_HPP
26 #define SHARE_VM_COMPILER_CODECACHE_INLINE_HPP
27 
28 #include "code/codeCache.hpp"
29 #include "code/nativeInst.hpp"
30 
31 inline CodeBlob* CodeCache::find_blob_fast(void* pc) {
32   int slot = 0;
33   return find_blob_and_oopmap(pc, slot);
34 }
35 
36 inline CodeBlob* CodeCache::find_blob_and_oopmap(void* pc, int& slot) {
37   NativePostCallNop* nop = nativePostCallNop_at((address) pc);
38   if (LIKELY(nop != NULL)) {
39     CodeBlob* cb;
40     if (LIKELY(nop->displacement() != 0)) {
41       int offset = (nop->displacement() & 0xffffff);
42       cb = (CodeBlob*) ((address) pc - offset);
43       slot = ((nop->displacement() >> 24) & 0xff);
44       // tty->print_cr(">>> PATCHED 22"); cb->print_on(tty);
45     } else {
46       // tty->print_cr(">>> patching");
47       cb = CodeCache::patch_nop(nop, pc, slot);
48     }
49     assert(cb != NULL, "must be");
50     return cb;
51   } else {
52     CodeBlob* cb = CodeCache::find_blob(pc);
53     slot = -1;
54     return cb;
55   }
56 }
57 
58 inline int CodeCache::find_oopmap_slot_fast(void* pc) {
59   int slot = -1;
60   NativePostCallNop* nop = nativePostCallNop_at((address) pc);
61   if (LIKELY(nop != NULL)) {
62     if (LIKELY(nop->displacement() != 0)) {
63       slot = ((nop->displacement() >> 24) & 0xff);
64     }
65   }
66   return slot;
67 }
68 
69 #endif