src/hotspot/share/runtime/icache.hpp
author iklam
Fri, 29 Nov 2019 14:11:50 -0800
changeset 59328 f280911d3427
parent 53244 9807daeb47c4
permissions -rw-r--r--
8230385: [cds] No message is logged when shared image cannot be used due to mismatched configuration Reviewed-by: stuefe, dholmes, ccheung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    25
#ifndef SHARE_RUNTIME_ICACHE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    26
#define SHARE_RUNTIME_ICACHE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/stubCodeGenerator.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 29180
diff changeset
    30
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Interface for updating the instruction cache.  Whenever the VM modifies
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// code, part of the processor instruction cache potentially has to be flushed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Default implementation is in icache.cpp, and can be hidden per-platform.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Most platforms must provide only ICacheStubGenerator::generate_icache_flush().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Platforms that don't require icache flushing can just nullify the public
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// members of AbstractICache in their ICache class.  AbstractICache should never
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// be referenced other than by deriving the ICache class from it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// The code for the ICache class and for generate_icache_flush() must be in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// architecture-specific files, i.e., icache_<arch>.hpp/.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class AbstractICache : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // The flush stub signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  typedef int (*flush_icache_stub_t)(address addr, int lines, int magic);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // The flush stub function address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  static flush_icache_stub_t _flush_icache_stub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Call the flush stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  static void call_flush_stub(address start, int lines);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    stub_size      = 0, // Size of the icache flush stub in bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    line_size      = 0, // Icache line size in bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    log2_line_size = 0  // log2(line_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  static void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static void invalidate_word(address addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  static void invalidate_range(address start, int nbytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// Must be included before the definition of ICacheStubGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// because ICacheStubGenerator uses ICache definitions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 29180
diff changeset
    72
#include CPU_HEADER(icache)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
class ICacheStubGenerator : public StubCodeGenerator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  ICacheStubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Generate the icache flush stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Since we cannot flush the cache when this stub is generated,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // it must be generated first, and just to be sure, we do extra
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // work to allow a check that these instructions got executed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // The flush stub has three parameters (see flush_icache_stub_t).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  //   addr  - Start address, must be aligned at log2_line_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  //   lines - Number of line_size icache lines to flush
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //   magic - Magic number copied to result register to make sure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  //           the stub executed properly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // A template for generate_icache_flush is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  //    #define __ _masm->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  //    void ICacheStubGenerator::generate_icache_flush(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  //      ICache::flush_icache_stub_t* flush_icache_stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  //    ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  //      StubCodeMark mark(this, "ICache", "flush_icache_stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  //      address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  //      // emit flush stub asm code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  //      // Must be set here so StubCodeMark destructor can call the flush stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  //      *flush_icache_stub = (ICache::flush_icache_stub_t)start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  //    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  //    #undef __
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // The first use of flush_icache_stub must apply it to itself.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // StubCodeMark destructor in generate_icache_flush will call Assembler::flush,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // which in turn will call invalidate_range (see asm/assembler.cpp), which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // in turn will call the flush stub *before* generate_icache_flush returns.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // The usual method of having generate_icache_flush return the address of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // stub to its caller, which would then, e.g., store that address in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // flush_icache_stub, won't work.  generate_icache_flush must itself set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // flush_icache_stub to the address of the stub it generates before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // the StubCodeMark destructor is invoked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void generate_icache_flush(ICache::flush_icache_stub_t* flush_icache_stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   122
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
   123
#endif // SHARE_RUNTIME_ICACHE_HPP