hotspot/src/share/vm/opto/locknode.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 239 fb31825d5444
permissions -rw-r--r--
Initial load
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 1999-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/_locknode.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
const RegMask &BoxLockNode::in_RegMask(uint i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  return _inmask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
const RegMask &BoxLockNode::out_RegMask() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  return *Matcher::idealreg2regmask[Op_RegP];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
uint BoxLockNode::size_of() const { return sizeof(*this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
BoxLockNode::BoxLockNode( int slot ) : Node( Compile::current()->root() ), _slot(slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  init_class_id(Class_BoxLock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  init_flags(Flag_rematerialize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  OptoReg::Name reg = OptoReg::stack2reg(_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _inmask.Insert(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
uint BoxLockNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  const BoxLockNode &bn = (const BoxLockNode &)n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  return bn._slot == _slot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
OptoReg::Name BoxLockNode::stack_slot(Node* box_node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Chase down the BoxNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  while (!box_node->is_BoxLock()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    //    if (box_node->is_SpillCopy()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    //      Node *m = box_node->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    //      if (m->is_Mach() && m->as_Mach()->ideal_Opcode() == Op_StoreP) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    //        box_node = m->in(m->as_Mach()->operand_index(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    //        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    assert(box_node->is_SpillCopy() || box_node->is_Phi(), "Bad spill of Lock.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    box_node = box_node->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  return box_node->in_RegMask(0).find_first_elem();
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
//-----------------------------hash--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
uint FastLockNode::hash() const { return NO_HASH; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
uint FastLockNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  return (&n == this);                // Always fail except on self
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//-----------------------------hash--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
uint FastUnlockNode::hash() const { return NO_HASH; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
uint FastUnlockNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  return (&n == this);                // Always fail except on self
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// Create a counter which counts the number of times this lock is acquired
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void FastLockNode::create_lock_counter(JVMState* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  BiasedLockingNamedCounter* blnc = (BiasedLockingNamedCounter*)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
           OptoRuntime::new_named_counter(state, NamedCounter::BiasedLockingCounter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _counters = blnc->counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
//------------------------------do_monitor_enter-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void Parse::do_monitor_enter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  kill_dead_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Null check; get casted pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  Node *obj = do_null_check(peek(), T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Check for locking null object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  if (stopped()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // the monitor object is not part of debug info expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Insert a FastLockNode which takes as arguments the current thread pointer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // the obj pointer & the address of the stack slot pair used for the lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  shared_lock(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
//------------------------------do_monitor_exit--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
void Parse::do_monitor_exit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  kill_dead_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  pop();                        // Pop oop to unlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Because monitors are guarenteed paired (else we bail out), we know
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // the matching Lock for this Unlock.  Hence we know there is no need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // for a null check on Unlock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  shared_unlock(map()->peek_monitor_box(), map()->peek_monitor_obj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}