hotspot/src/share/vm/runtime/icache.cpp
author phh
Wed, 28 Oct 2009 16:25:51 -0400
changeset 4434 4b41e5b42f81
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6887571: Increase default heap config sizes Summary: Apply modification of existing server heap size ergo to all collectors except CMS. Reviewed-by: jmasa, ysr, xlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_icache.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// The flush stub function address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
AbstractICache::flush_icache_stub_t AbstractICache::_flush_icache_stub = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
void AbstractICache::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // Making this stub must be FIRST use of assembler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  BufferBlob* b = BufferBlob::create("flush_icache_stub", ICache::stub_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  CodeBuffer c(b->instructions_begin(), b->instructions_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  ICacheStubGenerator g(&c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  g.generate_icache_flush(&_flush_icache_stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // The first use of flush_icache_stub must apply it to itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // The StubCodeMark destructor in generate_icache_flush will
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // call Assembler::flush, which in turn will call invalidate_range,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // which will in turn call the flush stub.  Thus we don't need an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // explicit call to invalidate_range here.  This assumption is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // checked in invalidate_range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
void AbstractICache::call_flush_stub(address start, int lines) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // The business with the magic number is just a little security.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // We cannot call the flush stub when generating the flush stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // because it isn't there yet.  So, the stub also returns its third
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // parameter.  This is a cheap check that the stub was really executed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  static int magic = 0xbaadbabe;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int auto_magic = magic; // Make a local copy to avoid race condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int r = (*_flush_icache_stub)(start, lines, auto_magic);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  guarantee(r == auto_magic, "flush stub routine did not execute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  ++magic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
void AbstractICache::invalidate_word(address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Because this is called for instruction patching on the fly, long after
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // bootstrapping, we execute the stub directly.  Account for a 4-byte word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // spanning two cache lines by computing a start line address by rounding
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // addr down to a line_size boundary, and an end line address by adding
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // the word size - 1 and rounding the result down to a line_size boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // If we just added word size, we'd mistakenly flush the next cache line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // if the word to be flushed started in the last 4 bytes of the line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Doing that would segv if the next line weren't mapped.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  const int word_size_in_bytes = 4; // Always, regardless of platform
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  intptr_t start_line = ((intptr_t)addr + 0) & ~(ICache::line_size - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  intptr_t end_line   = ((intptr_t)addr + word_size_in_bytes - 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                                             & ~(ICache::line_size - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  (*_flush_icache_stub)((address)start_line, start_line == end_line ? 1 : 2, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
void AbstractICache::invalidate_range(address start, int nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  static bool firstTime = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if (firstTime) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    guarantee(start == CAST_FROM_FN_PTR(address, _flush_icache_stub),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
              "first flush should be for flush stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    firstTime = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  if (nbytes == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Align start address to an icache line boundary and transform
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // nbytes to an icache line count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  const uint line_offset = mask_address_bits(start, ICache::line_size-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  if (line_offset != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    start -= line_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    nbytes += line_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  call_flush_stub(start, round_to(nbytes, ICache::line_size) >>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                         ICache::log2_line_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// For init.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
void icache_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  ICache::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}