hotspot/src/share/vm/runtime/icache.cpp
author twisti
Fri, 02 Sep 2011 00:36:18 -0700
changeset 10510 ab626d1bdf53
parent 7397 5b173b4ca846
child 25495 aeb87692dfd0
permissions -rw-r--r--
7085404: JSR 292: VolatileCallSites should have push notification too Reviewed-by: never, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    26
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    27
#include "runtime/icache.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// The flush stub function address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
AbstractICache::flush_icache_stub_t AbstractICache::_flush_icache_stub = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
void AbstractICache::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // Making this stub must be FIRST use of assembler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  BufferBlob* b = BufferBlob::create("flush_icache_stub", ICache::stub_size);
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
    37
  CodeBuffer c(b);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  ICacheStubGenerator g(&c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  g.generate_icache_flush(&_flush_icache_stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // The first use of flush_icache_stub must apply it to itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // The StubCodeMark destructor in generate_icache_flush will
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // call Assembler::flush, which in turn will call invalidate_range,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // which will in turn call the flush stub.  Thus we don't need an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // explicit call to invalidate_range here.  This assumption is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // checked in invalidate_range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void AbstractICache::call_flush_stub(address start, int lines) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // The business with the magic number is just a little security.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // We cannot call the flush stub when generating the flush stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // because it isn't there yet.  So, the stub also returns its third
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // parameter.  This is a cheap check that the stub was really executed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static int magic = 0xbaadbabe;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int auto_magic = magic; // Make a local copy to avoid race condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int r = (*_flush_icache_stub)(start, lines, auto_magic);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  guarantee(r == auto_magic, "flush stub routine did not execute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  ++magic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
void AbstractICache::invalidate_word(address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Because this is called for instruction patching on the fly, long after
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // bootstrapping, we execute the stub directly.  Account for a 4-byte word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // spanning two cache lines by computing a start line address by rounding
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // addr down to a line_size boundary, and an end line address by adding
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // the word size - 1 and rounding the result down to a line_size boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // If we just added word size, we'd mistakenly flush the next cache line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // if the word to be flushed started in the last 4 bytes of the line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Doing that would segv if the next line weren't mapped.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  const int word_size_in_bytes = 4; // Always, regardless of platform
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  intptr_t start_line = ((intptr_t)addr + 0) & ~(ICache::line_size - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  intptr_t end_line   = ((intptr_t)addr + word_size_in_bytes - 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                                             & ~(ICache::line_size - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  (*_flush_icache_stub)((address)start_line, start_line == end_line ? 1 : 2, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void AbstractICache::invalidate_range(address start, int nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  static bool firstTime = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (firstTime) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    guarantee(start == CAST_FROM_FN_PTR(address, _flush_icache_stub),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
              "first flush should be for flush stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    firstTime = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  if (nbytes == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Align start address to an icache line boundary and transform
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // nbytes to an icache line count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  const uint line_offset = mask_address_bits(start, ICache::line_size-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  if (line_offset != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    start -= line_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    nbytes += line_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  call_flush_stub(start, round_to(nbytes, ICache::line_size) >>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                         ICache::log2_line_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// For init.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
void icache_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ICache::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
}