aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #ifndef SHARE_VM_RUNTIME_ICACHE_HPP aoqi@0: #define SHARE_VM_RUNTIME_ICACHE_HPP aoqi@0: aoqi@0: #include "memory/allocation.hpp" aoqi@0: #include "runtime/stubCodeGenerator.hpp" aoqi@0: aoqi@0: // Interface for updating the instruction cache. Whenever the VM modifies aoqi@0: // code, part of the processor instruction cache potentially has to be flushed. aoqi@0: aoqi@0: // Default implementation is in icache.cpp, and can be hidden per-platform. aoqi@0: // Most platforms must provide only ICacheStubGenerator::generate_icache_flush(). aoqi@0: // Platforms that don't require icache flushing can just nullify the public aoqi@0: // members of AbstractICache in their ICache class. AbstractICache should never aoqi@0: // be referenced other than by deriving the ICache class from it. aoqi@0: // aoqi@0: // The code for the ICache class and for generate_icache_flush() must be in aoqi@0: // architecture-specific files, i.e., icache_.hpp/.cpp aoqi@0: aoqi@0: class AbstractICache : AllStatic { aoqi@0: public: aoqi@0: // The flush stub signature aoqi@0: typedef int (*flush_icache_stub_t)(address addr, int lines, int magic); aoqi@0: aoqi@0: protected: aoqi@0: // The flush stub function address aoqi@0: static flush_icache_stub_t _flush_icache_stub; aoqi@0: aoqi@0: // Call the flush stub aoqi@0: static void call_flush_stub(address start, int lines); aoqi@0: aoqi@0: public: aoqi@0: enum { aoqi@0: stub_size = 0, // Size of the icache flush stub in bytes aoqi@0: line_size = 0, // Icache line size in bytes aoqi@0: log2_line_size = 0 // log2(line_size) aoqi@0: }; aoqi@0: aoqi@0: static void initialize(); aoqi@0: static void invalidate_word(address addr); aoqi@0: static void invalidate_range(address start, int nbytes); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Must be included before the definition of ICacheStubGenerator aoqi@0: // because ICacheStubGenerator uses ICache definitions. aoqi@0: aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "icache_x86.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "icache_sparc.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_zero aoqi@0: # include "icache_zero.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "icache_arm.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "icache_ppc.hpp" aoqi@0: #endif aoqi@1: #ifdef TARGET_ARCH_mips aoqi@1: # include "icache_mips.hpp" aoqi@1: #endif aoqi@0: aoqi@0: aoqi@0: class ICacheStubGenerator : public StubCodeGenerator { aoqi@0: public: aoqi@0: ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {} aoqi@0: aoqi@0: // Generate the icache flush stub. aoqi@0: // aoqi@0: // Since we cannot flush the cache when this stub is generated, aoqi@0: // it must be generated first, and just to be sure, we do extra aoqi@0: // work to allow a check that these instructions got executed. aoqi@0: // aoqi@0: // The flush stub has three parameters (see flush_icache_stub_t). aoqi@0: // aoqi@0: // addr - Start address, must be aligned at log2_line_size aoqi@0: // lines - Number of line_size icache lines to flush aoqi@0: // magic - Magic number copied to result register to make sure aoqi@0: // the stub executed properly aoqi@0: // aoqi@0: // A template for generate_icache_flush is aoqi@0: // aoqi@0: // #define __ _masm-> aoqi@0: // aoqi@0: // void ICacheStubGenerator::generate_icache_flush( aoqi@0: // ICache::flush_icache_stub_t* flush_icache_stub aoqi@0: // ) { aoqi@0: // StubCodeMark mark(this, "ICache", "flush_icache_stub"); aoqi@0: // aoqi@0: // address start = __ pc(); aoqi@0: // aoqi@0: // // emit flush stub asm code aoqi@0: // aoqi@0: // // Must be set here so StubCodeMark destructor can call the flush stub. aoqi@0: // *flush_icache_stub = (ICache::flush_icache_stub_t)start; aoqi@0: // }; aoqi@0: // aoqi@0: // #undef __ aoqi@0: // aoqi@0: // The first use of flush_icache_stub must apply it to itself. The aoqi@0: // StubCodeMark destructor in generate_icache_flush will call Assembler::flush, aoqi@0: // which in turn will call invalidate_range (see asm/assembler.cpp), which aoqi@0: // in turn will call the flush stub *before* generate_icache_flush returns. aoqi@0: // The usual method of having generate_icache_flush return the address of the aoqi@0: // stub to its caller, which would then, e.g., store that address in aoqi@0: // flush_icache_stub, won't work. generate_icache_flush must itself set aoqi@0: // flush_icache_stub to the address of the stub it generates before aoqi@0: // the StubCodeMark destructor is invoked. aoqi@0: aoqi@0: void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_RUNTIME_ICACHE_HPP