author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46625 | hotspot/src/share/vm/runtime/icache.cpp@edefffab74e2 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
6418 | 2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "memory/resourceArea.hpp" |
|
27 |
#include "runtime/icache.hpp" |
|
46625 | 28 |
#include "utilities/align.hpp" |
1 | 29 |
|
30 |
// The flush stub function address |
|
31 |
AbstractICache::flush_icache_stub_t AbstractICache::_flush_icache_stub = NULL; |
|
32 |
||
33 |
void AbstractICache::initialize() { |
|
34 |
// Making this stub must be FIRST use of assembler |
|
35 |
ResourceMark rm; |
|
36 |
||
37 |
BufferBlob* b = BufferBlob::create("flush_icache_stub", ICache::stub_size); |
|
25495
aeb87692dfd0
8022968: Some codecache allocation failures don't result in invoking the sweeper
thartmann
parents:
7397
diff
changeset
|
38 |
if (b == NULL) { |
aeb87692dfd0
8022968: Some codecache allocation failures don't result in invoking the sweeper
thartmann
parents:
7397
diff
changeset
|
39 |
vm_exit_out_of_memory(ICache::stub_size, OOM_MALLOC_ERROR, "CodeCache: no space for flush_icache_stub"); |
aeb87692dfd0
8022968: Some codecache allocation failures don't result in invoking the sweeper
thartmann
parents:
7397
diff
changeset
|
40 |
} |
6418 | 41 |
CodeBuffer c(b); |
1 | 42 |
|
43 |
ICacheStubGenerator g(&c); |
|
44 |
g.generate_icache_flush(&_flush_icache_stub); |
|
45 |
||
46 |
// The first use of flush_icache_stub must apply it to itself. |
|
47 |
// The StubCodeMark destructor in generate_icache_flush will |
|
48 |
// call Assembler::flush, which in turn will call invalidate_range, |
|
49 |
// which will in turn call the flush stub. Thus we don't need an |
|
50 |
// explicit call to invalidate_range here. This assumption is |
|
51 |
// checked in invalidate_range. |
|
52 |
} |
|
53 |
||
54 |
void AbstractICache::call_flush_stub(address start, int lines) { |
|
55 |
// The business with the magic number is just a little security. |
|
56 |
// We cannot call the flush stub when generating the flush stub |
|
57 |
// because it isn't there yet. So, the stub also returns its third |
|
58 |
// parameter. This is a cheap check that the stub was really executed. |
|
59 |
static int magic = 0xbaadbabe; |
|
60 |
||
61 |
int auto_magic = magic; // Make a local copy to avoid race condition |
|
62 |
int r = (*_flush_icache_stub)(start, lines, auto_magic); |
|
63 |
guarantee(r == auto_magic, "flush stub routine did not execute"); |
|
64 |
++magic; |
|
65 |
} |
|
66 |
||
67 |
void AbstractICache::invalidate_word(address addr) { |
|
68 |
// Because this is called for instruction patching on the fly, long after |
|
69 |
// bootstrapping, we execute the stub directly. Account for a 4-byte word |
|
70 |
// spanning two cache lines by computing a start line address by rounding |
|
71 |
// addr down to a line_size boundary, and an end line address by adding |
|
72 |
// the word size - 1 and rounding the result down to a line_size boundary. |
|
73 |
// If we just added word size, we'd mistakenly flush the next cache line |
|
74 |
// if the word to be flushed started in the last 4 bytes of the line. |
|
75 |
// Doing that would segv if the next line weren't mapped. |
|
76 |
||
77 |
const int word_size_in_bytes = 4; // Always, regardless of platform |
|
78 |
||
79 |
intptr_t start_line = ((intptr_t)addr + 0) & ~(ICache::line_size - 1); |
|
80 |
intptr_t end_line = ((intptr_t)addr + word_size_in_bytes - 1) |
|
81 |
& ~(ICache::line_size - 1); |
|
82 |
(*_flush_icache_stub)((address)start_line, start_line == end_line ? 1 : 2, 0); |
|
83 |
} |
|
84 |
||
85 |
void AbstractICache::invalidate_range(address start, int nbytes) { |
|
86 |
static bool firstTime = true; |
|
87 |
if (firstTime) { |
|
88 |
guarantee(start == CAST_FROM_FN_PTR(address, _flush_icache_stub), |
|
89 |
"first flush should be for flush stub"); |
|
90 |
firstTime = false; |
|
91 |
return; |
|
92 |
} |
|
93 |
if (nbytes == 0) { |
|
94 |
return; |
|
95 |
} |
|
96 |
// Align start address to an icache line boundary and transform |
|
97 |
// nbytes to an icache line count. |
|
98 |
const uint line_offset = mask_address_bits(start, ICache::line_size-1); |
|
99 |
if (line_offset != 0) { |
|
100 |
start -= line_offset; |
|
101 |
nbytes += line_offset; |
|
102 |
} |
|
46620
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
25495
diff
changeset
|
103 |
call_flush_stub(start, align_up(nbytes, (int)ICache::line_size) >> |
1 | 104 |
ICache::log2_line_size); |
105 |
} |
|
106 |
||
107 |
// For init.cpp |
|
108 |
void icache_init() { |
|
109 |
ICache::initialize(); |
|
110 |
} |