hotspot/src/share/vm/opto/locknode.cpp
author johnc
Wed, 13 Apr 2011 17:56:43 -0700
changeset 9181 d32bbcce6b1f
parent 7397 5b173b4ca846
child 11445 3c768dca60f5
permissions -rw-r--r--
7035117: G1: nsk/stress/jni/jnistress002 fails with assertion failure Summary: Allow long type for offset in G1 code in compiler implementations of Unsafe.getObject Reviewed-by: never, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1999, 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: 2131
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
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: 2131
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "opto/locknode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "opto/parse.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/rootnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/runtime.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
const RegMask &BoxLockNode::in_RegMask(uint i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  return _inmask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
const RegMask &BoxLockNode::out_RegMask() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  return *Matcher::idealreg2regmask[Op_RegP];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
uint BoxLockNode::size_of() const { return sizeof(*this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
239
fb31825d5444 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 1
diff changeset
    42
BoxLockNode::BoxLockNode( int slot ) : Node( Compile::current()->root() ),
fb31825d5444 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 1
diff changeset
    43
                                       _slot(slot), _is_eliminated(false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  init_class_id(Class_BoxLock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  init_flags(Flag_rematerialize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  OptoReg::Name reg = OptoReg::stack2reg(_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _inmask.Insert(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
1613
be097ec639a2 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 670
diff changeset
    50
//-----------------------------hash--------------------------------------------
be097ec639a2 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 670
diff changeset
    51
uint BoxLockNode::hash() const {
be097ec639a2 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 670
diff changeset
    52
  return Node::hash() + _slot + (_is_eliminated ? Compile::current()->fixed_slots() : 0);
be097ec639a2 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 670
diff changeset
    53
}
be097ec639a2 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 670
diff changeset
    54
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
uint BoxLockNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  const BoxLockNode &bn = (const BoxLockNode &)n;
1613
be097ec639a2 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 670
diff changeset
    58
  return bn._slot == _slot && bn._is_eliminated == _is_eliminated;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
OptoReg::Name BoxLockNode::stack_slot(Node* box_node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Chase down the BoxNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  while (!box_node->is_BoxLock()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    //    if (box_node->is_SpillCopy()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    //      Node *m = box_node->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    //      if (m->is_Mach() && m->as_Mach()->ideal_Opcode() == Op_StoreP) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    //        box_node = m->in(m->as_Mach()->operand_index(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    //        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    assert(box_node->is_SpillCopy() || box_node->is_Phi(), "Bad spill of Lock.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    box_node = box_node->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  return box_node->in_RegMask(0).find_first_elem();
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 FastLockNode::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 FastLockNode::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
//-----------------------------hash--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
uint FastUnlockNode::hash() const { return NO_HASH; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
uint FastUnlockNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  return (&n == this);                // Always fail except on self
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
// Create a counter which counts the number of times this lock is acquired
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void FastLockNode::create_lock_counter(JVMState* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  BiasedLockingNamedCounter* blnc = (BiasedLockingNamedCounter*)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
           OptoRuntime::new_named_counter(state, NamedCounter::BiasedLockingCounter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _counters = blnc->counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
//------------------------------do_monitor_enter-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void Parse::do_monitor_enter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  kill_dead_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Null check; get casted pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  Node *obj = do_null_check(peek(), T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Check for locking null object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (stopped()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // the monitor object is not part of debug info expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Insert a FastLockNode which takes as arguments the current thread pointer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // the obj pointer & the address of the stack slot pair used for the lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  shared_lock(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
//------------------------------do_monitor_exit--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
void Parse::do_monitor_exit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  kill_dead_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  pop();                        // Pop oop to unlock
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1613
diff changeset
   127
  // Because monitors are guaranteed paired (else we bail out), we know
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // the matching Lock for this Unlock.  Hence we know there is no need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // for a null check on Unlock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  shared_unlock(map()->peek_monitor_box(), map()->peek_monitor_obj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}