src/share/vm/runtime/icache.hpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/icache.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,138 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_RUNTIME_ICACHE_HPP
    1.29 +#define SHARE_VM_RUNTIME_ICACHE_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "runtime/stubCodeGenerator.hpp"
    1.33 +
    1.34 +// Interface for updating the instruction cache.  Whenever the VM modifies
    1.35 +// code, part of the processor instruction cache potentially has to be flushed.
    1.36 +
    1.37 +// Default implementation is in icache.cpp, and can be hidden per-platform.
    1.38 +// Most platforms must provide only ICacheStubGenerator::generate_icache_flush().
    1.39 +// Platforms that don't require icache flushing can just nullify the public
    1.40 +// members of AbstractICache in their ICache class.  AbstractICache should never
    1.41 +// be referenced other than by deriving the ICache class from it.
    1.42 +//
    1.43 +// The code for the ICache class and for generate_icache_flush() must be in
    1.44 +// architecture-specific files, i.e., icache_<arch>.hpp/.cpp
    1.45 +
    1.46 +class AbstractICache : AllStatic {
    1.47 + public:
    1.48 +  // The flush stub signature
    1.49 +  typedef int (*flush_icache_stub_t)(address addr, int lines, int magic);
    1.50 +
    1.51 + protected:
    1.52 +  // The flush stub function address
    1.53 +  static flush_icache_stub_t _flush_icache_stub;
    1.54 +
    1.55 +  // Call the flush stub
    1.56 +  static void call_flush_stub(address start, int lines);
    1.57 +
    1.58 + public:
    1.59 +  enum {
    1.60 +    stub_size      = 0, // Size of the icache flush stub in bytes
    1.61 +    line_size      = 0, // Icache line size in bytes
    1.62 +    log2_line_size = 0  // log2(line_size)
    1.63 +  };
    1.64 +
    1.65 +  static void initialize();
    1.66 +  static void invalidate_word(address addr);
    1.67 +  static void invalidate_range(address start, int nbytes);
    1.68 +};
    1.69 +
    1.70 +
    1.71 +// Must be included before the definition of ICacheStubGenerator
    1.72 +// because ICacheStubGenerator uses ICache definitions.
    1.73 +
    1.74 +#ifdef TARGET_ARCH_x86
    1.75 +# include "icache_x86.hpp"
    1.76 +#endif
    1.77 +#ifdef TARGET_ARCH_sparc
    1.78 +# include "icache_sparc.hpp"
    1.79 +#endif
    1.80 +#ifdef TARGET_ARCH_zero
    1.81 +# include "icache_zero.hpp"
    1.82 +#endif
    1.83 +#ifdef TARGET_ARCH_arm
    1.84 +# include "icache_arm.hpp"
    1.85 +#endif
    1.86 +#ifdef TARGET_ARCH_ppc
    1.87 +# include "icache_ppc.hpp"
    1.88 +#endif
    1.89 +
    1.90 +
    1.91 +
    1.92 +class ICacheStubGenerator : public StubCodeGenerator {
    1.93 + public:
    1.94 +  ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
    1.95 +
    1.96 +  // Generate the icache flush stub.
    1.97 +  //
    1.98 +  // Since we cannot flush the cache when this stub is generated,
    1.99 +  // it must be generated first, and just to be sure, we do extra
   1.100 +  // work to allow a check that these instructions got executed.
   1.101 +  //
   1.102 +  // The flush stub has three parameters (see flush_icache_stub_t).
   1.103 +  //
   1.104 +  //   addr  - Start address, must be aligned at log2_line_size
   1.105 +  //   lines - Number of line_size icache lines to flush
   1.106 +  //   magic - Magic number copied to result register to make sure
   1.107 +  //           the stub executed properly
   1.108 +  //
   1.109 +  // A template for generate_icache_flush is
   1.110 +  //
   1.111 +  //    #define __ _masm->
   1.112 +  //
   1.113 +  //    void ICacheStubGenerator::generate_icache_flush(
   1.114 +  //      ICache::flush_icache_stub_t* flush_icache_stub
   1.115 +  //    ) {
   1.116 +  //      StubCodeMark mark(this, "ICache", "flush_icache_stub");
   1.117 +  //
   1.118 +  //      address start = __ pc();
   1.119 +  //
   1.120 +  //      // emit flush stub asm code
   1.121 +  //
   1.122 +  //      // Must be set here so StubCodeMark destructor can call the flush stub.
   1.123 +  //      *flush_icache_stub = (ICache::flush_icache_stub_t)start;
   1.124 +  //    };
   1.125 +  //
   1.126 +  //    #undef __
   1.127 +  //
   1.128 +  // The first use of flush_icache_stub must apply it to itself.  The
   1.129 +  // StubCodeMark destructor in generate_icache_flush will call Assembler::flush,
   1.130 +  // which in turn will call invalidate_range (see asm/assembler.cpp), which
   1.131 +  // in turn will call the flush stub *before* generate_icache_flush returns.
   1.132 +  // The usual method of having generate_icache_flush return the address of the
   1.133 +  // stub to its caller, which would then, e.g., store that address in
   1.134 +  // flush_icache_stub, won't work.  generate_icache_flush must itself set
   1.135 +  // flush_icache_stub to the address of the stub it generates before
   1.136 +  // the StubCodeMark destructor is invoked.
   1.137 +
   1.138 +  void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub);
   1.139 +};
   1.140 +
   1.141 +#endif // SHARE_VM_RUNTIME_ICACHE_HPP

mercurial