annotate src/share/vm/runtime/icache.cpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents f95d63e2154a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1748
3e8fbc61cee8 6978355: renaming for 6961697
twisti
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1748
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1748
diff changeset
26 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1748
diff changeset
27 #include "runtime/icache.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // The flush stub function address
a61af66fc99e Initial load
duke
parents:
diff changeset
30 AbstractICache::flush_icache_stub_t AbstractICache::_flush_icache_stub = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 void AbstractICache::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Making this stub must be FIRST use of assembler
a61af66fc99e Initial load
duke
parents:
diff changeset
34 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 BufferBlob* b = BufferBlob::create("flush_icache_stub", ICache::stub_size);
1748
3e8fbc61cee8 6978355: renaming for 6961697
twisti
parents: 1552
diff changeset
37 CodeBuffer c(b);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 ICacheStubGenerator g(&c);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 g.generate_icache_flush(&_flush_icache_stub);
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // The first use of flush_icache_stub must apply it to itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // The StubCodeMark destructor in generate_icache_flush will
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // call Assembler::flush, which in turn will call invalidate_range,
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // which will in turn call the flush stub. Thus we don't need an
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // explicit call to invalidate_range here. This assumption is
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // checked in invalidate_range.
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 void AbstractICache::call_flush_stub(address start, int lines) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // The business with the magic number is just a little security.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // We cannot call the flush stub when generating the flush stub
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // because it isn't there yet. So, the stub also returns its third
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // parameter. This is a cheap check that the stub was really executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 static int magic = 0xbaadbabe;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int auto_magic = magic; // Make a local copy to avoid race condition
a61af66fc99e Initial load
duke
parents:
diff changeset
58 int r = (*_flush_icache_stub)(start, lines, auto_magic);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 guarantee(r == auto_magic, "flush stub routine did not execute");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ++magic;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 void AbstractICache::invalidate_word(address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Because this is called for instruction patching on the fly, long after
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // bootstrapping, we execute the stub directly. Account for a 4-byte word
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // spanning two cache lines by computing a start line address by rounding
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // addr down to a line_size boundary, and an end line address by adding
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // the word size - 1 and rounding the result down to a line_size boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // If we just added word size, we'd mistakenly flush the next cache line
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // if the word to be flushed started in the last 4 bytes of the line.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // Doing that would segv if the next line weren't mapped.
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 const int word_size_in_bytes = 4; // Always, regardless of platform
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 intptr_t start_line = ((intptr_t)addr + 0) & ~(ICache::line_size - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 intptr_t end_line = ((intptr_t)addr + word_size_in_bytes - 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
77 & ~(ICache::line_size - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 (*_flush_icache_stub)((address)start_line, start_line == end_line ? 1 : 2, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void AbstractICache::invalidate_range(address start, int nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 static bool firstTime = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (firstTime) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 guarantee(start == CAST_FROM_FN_PTR(address, _flush_icache_stub),
a61af66fc99e Initial load
duke
parents:
diff changeset
85 "first flush should be for flush stub");
a61af66fc99e Initial load
duke
parents:
diff changeset
86 firstTime = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (nbytes == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Align start address to an icache line boundary and transform
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // nbytes to an icache line count.
a61af66fc99e Initial load
duke
parents:
diff changeset
94 const uint line_offset = mask_address_bits(start, ICache::line_size-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (line_offset != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 start -= line_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 nbytes += line_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 call_flush_stub(start, round_to(nbytes, ICache::line_size) >>
a61af66fc99e Initial load
duke
parents:
diff changeset
100 ICache::log2_line_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // For init.cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
104 void icache_init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 ICache::initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }