Path: blob/master/src/hotspot/share/runtime/icache.hpp
40951 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_RUNTIME_ICACHE_HPP25#define SHARE_RUNTIME_ICACHE_HPP2627#include "memory/allocation.hpp"28#include "runtime/stubCodeGenerator.hpp"29#include "utilities/macros.hpp"3031// Interface for updating the instruction cache. Whenever the VM modifies32// code, part of the processor instruction cache potentially has to be flushed.3334// Default implementation is in icache.cpp, and can be hidden per-platform.35// Most platforms must provide only ICacheStubGenerator::generate_icache_flush().36// Platforms that don't require icache flushing can just nullify the public37// members of AbstractICache in their ICache class. AbstractICache should never38// be referenced other than by deriving the ICache class from it.39//40// The code for the ICache class and for generate_icache_flush() must be in41// architecture-specific files, i.e., icache_<arch>.hpp/.cpp4243class AbstractICache : AllStatic {44public:45// The flush stub signature46typedef int (*flush_icache_stub_t)(address addr, int lines, int magic);4748protected:49// The flush stub function address50static flush_icache_stub_t _flush_icache_stub;5152// Call the flush stub53static void call_flush_stub(address start, int lines);5455public:56enum {57stub_size = 0, // Size of the icache flush stub in bytes58line_size = 0, // Icache line size in bytes59log2_line_size = 0 // log2(line_size)60};6162static void initialize();63static void invalidate_word(address addr);64static void invalidate_range(address start, int nbytes);65};666768// Must be included before the definition of ICacheStubGenerator69// because ICacheStubGenerator uses ICache definitions.7071#include CPU_HEADER(icache)7273class ICacheStubGenerator : public StubCodeGenerator {74public:75ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}7677// Generate the icache flush stub.78//79// Since we cannot flush the cache when this stub is generated,80// it must be generated first, and just to be sure, we do extra81// work to allow a check that these instructions got executed.82//83// The flush stub has three parameters (see flush_icache_stub_t).84//85// addr - Start address, must be aligned at log2_line_size86// lines - Number of line_size icache lines to flush87// magic - Magic number copied to result register to make sure88// the stub executed properly89//90// A template for generate_icache_flush is91//92// #define __ _masm->93//94// void ICacheStubGenerator::generate_icache_flush(95// ICache::flush_icache_stub_t* flush_icache_stub96// ) {97// StubCodeMark mark(this, "ICache", "flush_icache_stub");98//99// address start = __ pc();100//101// // emit flush stub asm code102//103// // Must be set here so StubCodeMark destructor can call the flush stub.104// *flush_icache_stub = (ICache::flush_icache_stub_t)start;105// };106//107// #undef __108//109// The first use of flush_icache_stub must apply it to itself. The110// StubCodeMark destructor in generate_icache_flush will call Assembler::flush,111// which in turn will call invalidate_range (see asm/assembler.cpp), which112// in turn will call the flush stub *before* generate_icache_flush returns.113// The usual method of having generate_icache_flush return the address of the114// stub to its caller, which would then, e.g., store that address in115// flush_icache_stub, won't work. generate_icache_flush must itself set116// flush_icache_stub to the address of the stub it generates before117// the StubCodeMark destructor is invoked.118119void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub);120};121122#endif // SHARE_RUNTIME_ICACHE_HPP123124125