src/share/vm/runtime/icache.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial