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