Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/icache.hpp
32285 views
/*1* Copyright (c) 1997, 2011, 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_VM_RUNTIME_ICACHE_HPP25#define SHARE_VM_RUNTIME_ICACHE_HPP2627#include "memory/allocation.hpp"28#include "runtime/stubCodeGenerator.hpp"2930// Interface for updating the instruction cache. Whenever the VM modifies31// code, part of the processor instruction cache potentially has to be flushed.3233// Default implementation is in icache.cpp, and can be hidden per-platform.34// Most platforms must provide only ICacheStubGenerator::generate_icache_flush().35// Platforms that don't require icache flushing can just nullify the public36// members of AbstractICache in their ICache class. AbstractICache should never37// be referenced other than by deriving the ICache class from it.38//39// The code for the ICache class and for generate_icache_flush() must be in40// architecture-specific files, i.e., icache_<arch>.hpp/.cpp4142class AbstractICache : AllStatic {43public:44// The flush stub signature45typedef int (*flush_icache_stub_t)(address addr, int lines, int magic);4647protected:48// The flush stub function address49static flush_icache_stub_t _flush_icache_stub;5051// Call the flush stub52static void call_flush_stub(address start, int lines);5354public:55enum {56stub_size = 0, // Size of the icache flush stub in bytes57line_size = 0, // Icache line size in bytes58log2_line_size = 0 // log2(line_size)59};6061static void initialize();62static void invalidate_word(address addr);63static void invalidate_range(address start, int nbytes);64};656667// Must be included before the definition of ICacheStubGenerator68// because ICacheStubGenerator uses ICache definitions.6970#ifdef TARGET_ARCH_x8671# include "icache_x86.hpp"72#endif73#ifdef TARGET_ARCH_aarch3274# include "icache_aarch32.hpp"75#endif76#ifdef TARGET_ARCH_aarch6477# include "icache_aarch64.hpp"78#endif79#ifdef TARGET_ARCH_sparc80# include "icache_sparc.hpp"81#endif82#ifdef TARGET_ARCH_zero83# include "icache_zero.hpp"84#endif85#ifdef TARGET_ARCH_arm86# include "icache_arm.hpp"87#endif88#ifdef TARGET_ARCH_ppc89# include "icache_ppc.hpp"90#endif91929394class ICacheStubGenerator : public StubCodeGenerator {95public:96ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}9798// Generate the icache flush stub.99//100// Since we cannot flush the cache when this stub is generated,101// it must be generated first, and just to be sure, we do extra102// work to allow a check that these instructions got executed.103//104// The flush stub has three parameters (see flush_icache_stub_t).105//106// addr - Start address, must be aligned at log2_line_size107// lines - Number of line_size icache lines to flush108// magic - Magic number copied to result register to make sure109// the stub executed properly110//111// A template for generate_icache_flush is112//113// #define __ _masm->114//115// void ICacheStubGenerator::generate_icache_flush(116// ICache::flush_icache_stub_t* flush_icache_stub117// ) {118// StubCodeMark mark(this, "ICache", "flush_icache_stub");119//120// address start = __ pc();121//122// // emit flush stub asm code123//124// // Must be set here so StubCodeMark destructor can call the flush stub.125// *flush_icache_stub = (ICache::flush_icache_stub_t)start;126// };127//128// #undef __129//130// The first use of flush_icache_stub must apply it to itself. The131// StubCodeMark destructor in generate_icache_flush will call Assembler::flush,132// which in turn will call invalidate_range (see asm/assembler.cpp), which133// in turn will call the flush stub *before* generate_icache_flush returns.134// The usual method of having generate_icache_flush return the address of the135// stub to its caller, which would then, e.g., store that address in136// flush_icache_stub, won't work. generate_icache_flush must itself set137// flush_icache_stub to the address of the stub it generates before138// the StubCodeMark destructor is invoked.139140void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub);141};142143#endif // SHARE_VM_RUNTIME_ICACHE_HPP144145146