src/share/vm/runtime/icache.cpp

Wed, 18 Sep 2013 07:02:10 -0700

author
dcubed
date
Wed, 18 Sep 2013 07:02:10 -0700
changeset 5743
63147986a428
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
permissions
-rw-r--r--

8019835: Strings interned in different threads equal but does not ==
Summary: Add -XX:+VerifyStringTableAtExit option and code to verify StringTable invariants.
Reviewed-by: rdurbin, sspitsyn, coleenp

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

mercurial