1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/icache.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,115 @@ 1.4 +/* 1.5 + * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Interface for updating the instruction cache. Whenever the VM modifies 1.29 +// code, part of the processor instruction cache potentially has to be flushed. 1.30 + 1.31 +// Default implementation is in icache.cpp, and can be hidden per-platform. 1.32 +// Most platforms must provide only ICacheStubGenerator::generate_icache_flush(). 1.33 +// Platforms that don't require icache flushing can just nullify the public 1.34 +// members of AbstractICache in their ICache class. AbstractICache should never 1.35 +// be referenced other than by deriving the ICache class from it. 1.36 +// 1.37 +// The code for the ICache class and for generate_icache_flush() must be in 1.38 +// architecture-specific files, i.e., icache_<arch>.hpp/.cpp 1.39 + 1.40 +class AbstractICache : AllStatic { 1.41 + public: 1.42 + // The flush stub signature 1.43 + typedef int (*flush_icache_stub_t)(address addr, int lines, int magic); 1.44 + 1.45 + protected: 1.46 + // The flush stub function address 1.47 + static flush_icache_stub_t _flush_icache_stub; 1.48 + 1.49 + // Call the flush stub 1.50 + static void call_flush_stub(address start, int lines); 1.51 + 1.52 + public: 1.53 + enum { 1.54 + stub_size = 0, // Size of the icache flush stub in bytes 1.55 + line_size = 0, // Icache line size in bytes 1.56 + log2_line_size = 0 // log2(line_size) 1.57 + }; 1.58 + 1.59 + static void initialize(); 1.60 + static void invalidate_word(address addr); 1.61 + static void invalidate_range(address start, int nbytes); 1.62 +}; 1.63 + 1.64 + 1.65 +// Must be included before the definition of ICacheStubGenerator 1.66 +// because ICacheStubGenerator uses ICache definitions. 1.67 + 1.68 +#include "incls/_icache_pd.hpp.incl" 1.69 + 1.70 + 1.71 +class ICacheStubGenerator : public StubCodeGenerator { 1.72 + public: 1.73 + ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {} 1.74 + 1.75 + // Generate the icache flush stub. 1.76 + // 1.77 + // Since we cannot flush the cache when this stub is generated, 1.78 + // it must be generated first, and just to be sure, we do extra 1.79 + // work to allow a check that these instructions got executed. 1.80 + // 1.81 + // The flush stub has three parameters (see flush_icache_stub_t). 1.82 + // 1.83 + // addr - Start address, must be aligned at log2_line_size 1.84 + // lines - Number of line_size icache lines to flush 1.85 + // magic - Magic number copied to result register to make sure 1.86 + // the stub executed properly 1.87 + // 1.88 + // A template for generate_icache_flush is 1.89 + // 1.90 + // #define __ _masm-> 1.91 + // 1.92 + // void ICacheStubGenerator::generate_icache_flush( 1.93 + // ICache::flush_icache_stub_t* flush_icache_stub 1.94 + // ) { 1.95 + // StubCodeMark mark(this, "ICache", "flush_icache_stub"); 1.96 + // 1.97 + // address start = __ pc(); 1.98 + // 1.99 + // // emit flush stub asm code 1.100 + // 1.101 + // // Must be set here so StubCodeMark destructor can call the flush stub. 1.102 + // *flush_icache_stub = (ICache::flush_icache_stub_t)start; 1.103 + // }; 1.104 + // 1.105 + // #undef __ 1.106 + // 1.107 + // The first use of flush_icache_stub must apply it to itself. The 1.108 + // StubCodeMark destructor in generate_icache_flush will call Assembler::flush, 1.109 + // which in turn will call invalidate_range (see asm/assembler.cpp), which 1.110 + // in turn will call the flush stub *before* generate_icache_flush returns. 1.111 + // The usual method of having generate_icache_flush return the address of the 1.112 + // stub to its caller, which would then, e.g., store that address in 1.113 + // flush_icache_stub, won't work. generate_icache_flush must itself set 1.114 + // flush_icache_stub to the address of the stub it generates before 1.115 + // the StubCodeMark destructor is invoked. 1.116 + 1.117 + void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub); 1.118 +};