1 /* 2 * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 // Interface for updating the instruction cache. Whenever the VM modifies 26 // code, part of the processor instruction cache potentially has to be flushed. 27 28 // Default implementation is in icache.cpp, and can be hidden per-platform. 29 // Most platforms must provide only ICacheStubGenerator::generate_icache_flush(). 30 // Platforms that don't require icache flushing can just nullify the public 31 // members of AbstractICache in their ICache class. AbstractICache should never 32 // be referenced other than by deriving the ICache class from it. 33 // 34 // The code for the ICache class and for generate_icache_flush() must be in 35 // architecture-specific files, i.e., icache_<arch>.hpp/.cpp 36 37 class AbstractICache : AllStatic { 38 public: 39 // The flush stub signature 40 typedef int (*flush_icache_stub_t)(address addr, int lines, int magic); 41 42 protected: 43 // The flush stub function address 44 static flush_icache_stub_t _flush_icache_stub; 45 46 // Call the flush stub 47 static void call_flush_stub(address start, int lines); 48 49 public: 50 enum { 51 stub_size = 0, // Size of the icache flush stub in bytes 52 line_size = 0, // Icache line size in bytes 53 log2_line_size = 0 // log2(line_size) 54 }; 55 56 static void initialize(); 57 static void invalidate_word(address addr); 58 static void invalidate_range(address start, int nbytes); 59 }; 60 61 62 // Must be included before the definition of ICacheStubGenerator 63 // because ICacheStubGenerator uses ICache definitions. 64 65 #include "incls/_icache_pd.hpp.incl" 66 67 68 class ICacheStubGenerator : public StubCodeGenerator { 69 public: 70 ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {} 71 72 // Generate the icache flush stub. 73 // 74 // Since we cannot flush the cache when this stub is generated, 75 // it must be generated first, and just to be sure, we do extra 76 // work to allow a check that these instructions got executed. 77 // 78 // The flush stub has three parameters (see flush_icache_stub_t). 79 // 80 // addr - Start address, must be aligned at log2_line_size 81 // lines - Number of line_size icache lines to flush 82 // magic - Magic number copied to result register to make sure 83 // the stub executed properly 84 // 85 // A template for generate_icache_flush is 96 // // emit flush stub asm code 97 // 98 // // Must be set here so StubCodeMark destructor can call the flush stub. 99 // *flush_icache_stub = (ICache::flush_icache_stub_t)start; 100 // }; 101 // 102 // #undef __ 103 // 104 // The first use of flush_icache_stub must apply it to itself. The 105 // StubCodeMark destructor in generate_icache_flush will call Assembler::flush, 106 // which in turn will call invalidate_range (see asm/assembler.cpp), which 107 // in turn will call the flush stub *before* generate_icache_flush returns. 108 // The usual method of having generate_icache_flush return the address of the 109 // stub to its caller, which would then, e.g., store that address in 110 // flush_icache_stub, won't work. generate_icache_flush must itself set 111 // flush_icache_stub to the address of the stub it generates before 112 // the StubCodeMark destructor is invoked. 113 114 void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub); 115 }; | 1 /* 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_RUNTIME_ICACHE_HPP 26 #define SHARE_VM_RUNTIME_ICACHE_HPP 27 28 #include "memory/allocation.hpp" 29 #include "runtime/stubCodeGenerator.hpp" 30 31 // Interface for updating the instruction cache. Whenever the VM modifies 32 // code, part of the processor instruction cache potentially has to be flushed. 33 34 // 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 public 37 // members of AbstractICache in their ICache class. AbstractICache should never 38 // 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 in 41 // architecture-specific files, i.e., icache_<arch>.hpp/.cpp 42 43 class AbstractICache : AllStatic { 44 public: 45 // The flush stub signature 46 typedef int (*flush_icache_stub_t)(address addr, int lines, int magic); 47 48 protected: 49 // The flush stub function address 50 static flush_icache_stub_t _flush_icache_stub; 51 52 // Call the flush stub 53 static void call_flush_stub(address start, int lines); 54 55 public: 56 enum { 57 stub_size = 0, // Size of the icache flush stub in bytes 58 line_size = 0, // Icache line size in bytes 59 log2_line_size = 0 // log2(line_size) 60 }; 61 62 static void initialize(); 63 static void invalidate_word(address addr); 64 static void invalidate_range(address start, int nbytes); 65 }; 66 67 68 // Must be included before the definition of ICacheStubGenerator 69 // because ICacheStubGenerator uses ICache definitions. 70 71 #ifdef TARGET_ARCH_x86 72 # include "icache_x86.hpp" 73 #endif 74 #ifdef TARGET_ARCH_sparc 75 # include "icache_sparc.hpp" 76 #endif 77 #ifdef TARGET_ARCH_zero 78 # include "icache_zero.hpp" 79 #endif 80 81 82 83 class ICacheStubGenerator : public StubCodeGenerator { 84 public: 85 ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {} 86 87 // Generate the icache flush stub. 88 // 89 // Since we cannot flush the cache when this stub is generated, 90 // it must be generated first, and just to be sure, we do extra 91 // work to allow a check that these instructions got executed. 92 // 93 // The flush stub has three parameters (see flush_icache_stub_t). 94 // 95 // addr - Start address, must be aligned at log2_line_size 96 // lines - Number of line_size icache lines to flush 97 // magic - Magic number copied to result register to make sure 98 // the stub executed properly 99 // 100 // A template for generate_icache_flush is 111 // // emit flush stub asm code 112 // 113 // // Must be set here so StubCodeMark destructor can call the flush stub. 114 // *flush_icache_stub = (ICache::flush_icache_stub_t)start; 115 // }; 116 // 117 // #undef __ 118 // 119 // The first use of flush_icache_stub must apply it to itself. The 120 // StubCodeMark destructor in generate_icache_flush will call Assembler::flush, 121 // which in turn will call invalidate_range (see asm/assembler.cpp), which 122 // in turn will call the flush stub *before* generate_icache_flush returns. 123 // The usual method of having generate_icache_flush return the address of the 124 // stub to its caller, which would then, e.g., store that address in 125 // flush_icache_stub, won't work. generate_icache_flush must itself set 126 // flush_icache_stub to the address of the stub it generates before 127 // the StubCodeMark destructor is invoked. 128 129 void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub); 130 }; 131 132 #endif // SHARE_VM_RUNTIME_ICACHE_HPP |