hotspot/src/share/vm/prims/jvmtiRawMonitor.hpp
author acorn
Fri, 22 Oct 2010 15:59:34 -0400
changeset 6975 dc9b63952682
child 7397 5b173b4ca846
permissions -rw-r--r--
6988353: refactor contended sync subsystem Summary: reduce complexity by factoring synchronizer.cpp Reviewed-by: dholmes, never, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     1
/*
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     2
 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     4
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     8
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    13
 * accompanied this code).
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    14
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    18
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    21
 * questions.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    22
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    23
 */
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    24
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    25
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    26
// class JvmtiRawMonitor
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    27
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    28
// Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    29
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    30
// Wrapper for ObjectMonitor class that saves the Monitor's name
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    31
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    32
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    33
class JvmtiRawMonitor : public ObjectMonitor  {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    34
private:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    35
  int           _magic;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    36
  char *        _name;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    37
  // JVMTI_RM_MAGIC is set in contructor and unset in destructor.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    38
  enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    39
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    40
  int       SimpleEnter (Thread * Self) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    41
  int       SimpleExit  (Thread * Self) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    42
  int       SimpleWait  (Thread * Self, jlong millis) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    43
  int       SimpleNotify (Thread * Self, bool All) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    44
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    45
public:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    46
  JvmtiRawMonitor(const char *name);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    47
  ~JvmtiRawMonitor();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    48
  int       raw_enter(TRAPS);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    49
  int       raw_exit(TRAPS);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    50
  int       raw_wait(jlong millis, bool interruptable, TRAPS);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    51
  int       raw_notify(TRAPS);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    52
  int       raw_notifyAll(TRAPS);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    53
  int            magic()   { return _magic;  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    54
  const char *get_name()   { return _name; }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    55
  bool        is_valid();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    56
};
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    57
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    58
// Onload pending raw monitors
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    59
// Class is used to cache onload or onstart monitor enter
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    60
// which will transition into real monitor when
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    61
// VM is fully initialized.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    62
class JvmtiPendingMonitors : public AllStatic {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    63
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    64
private:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    65
  static GrowableArray<JvmtiRawMonitor*> *_monitors; // Cache raw monitor enter
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    66
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    67
  inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    68
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    69
  static void dispose() {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    70
    delete monitors();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    71
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    72
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    73
public:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    74
  static void enter(JvmtiRawMonitor *monitor) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    75
    monitors()->append(monitor);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    76
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    77
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    78
  static int count() {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    79
    return monitors()->length();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    80
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    81
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    82
  static void destroy(JvmtiRawMonitor *monitor) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    83
    while (monitors()->contains(monitor)) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    84
      monitors()->remove(monitor);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    85
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    86
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    87
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    88
  // Return false if monitor is not found in the list.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    89
  static bool exit(JvmtiRawMonitor *monitor) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    90
    if (monitors()->contains(monitor)) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    91
      monitors()->remove(monitor);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    92
      return true;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    93
    } else {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    94
      return false;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    95
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    96
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    97
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    98
  static void transition_raw_monitors();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    99
};