src/share/vm/prims/jvmtiRawMonitor.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/prims/jvmtiRawMonitor.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_PRIMS_JVMTIRAWMONITOR_HPP
    1.29 +#define SHARE_VM_PRIMS_JVMTIRAWMONITOR_HPP
    1.30 +
    1.31 +#include "runtime/objectMonitor.hpp"
    1.32 +#include "utilities/growableArray.hpp"
    1.33 +
    1.34 +//
    1.35 +// class JvmtiRawMonitor
    1.36 +//
    1.37 +// Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
    1.38 +//
    1.39 +// Wrapper for ObjectMonitor class that saves the Monitor's name
    1.40 +//
    1.41 +
    1.42 +class JvmtiRawMonitor : public ObjectMonitor  {
    1.43 +private:
    1.44 +  int           _magic;
    1.45 +  char *        _name;
    1.46 +  // JVMTI_RM_MAGIC is set in contructor and unset in destructor.
    1.47 +  enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
    1.48 +
    1.49 +  int       SimpleEnter (Thread * Self) ;
    1.50 +  int       SimpleExit  (Thread * Self) ;
    1.51 +  int       SimpleWait  (Thread * Self, jlong millis) ;
    1.52 +  int       SimpleNotify (Thread * Self, bool All) ;
    1.53 +
    1.54 +public:
    1.55 +  JvmtiRawMonitor(const char *name);
    1.56 +  ~JvmtiRawMonitor();
    1.57 +  int       raw_enter(TRAPS);
    1.58 +  int       raw_exit(TRAPS);
    1.59 +  int       raw_wait(jlong millis, bool interruptable, TRAPS);
    1.60 +  int       raw_notify(TRAPS);
    1.61 +  int       raw_notifyAll(TRAPS);
    1.62 +  int            magic()   { return _magic;  }
    1.63 +  const char *get_name()   { return _name; }
    1.64 +  bool        is_valid();
    1.65 +};
    1.66 +
    1.67 +// Onload pending raw monitors
    1.68 +// Class is used to cache onload or onstart monitor enter
    1.69 +// which will transition into real monitor when
    1.70 +// VM is fully initialized.
    1.71 +class JvmtiPendingMonitors : public AllStatic {
    1.72 +
    1.73 +private:
    1.74 +  static GrowableArray<JvmtiRawMonitor*> *_monitors; // Cache raw monitor enter
    1.75 +
    1.76 +  inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; }
    1.77 +
    1.78 +  static void dispose() {
    1.79 +    delete monitors();
    1.80 +  }
    1.81 +
    1.82 +public:
    1.83 +  static void enter(JvmtiRawMonitor *monitor) {
    1.84 +    monitors()->append(monitor);
    1.85 +  }
    1.86 +
    1.87 +  static int count() {
    1.88 +    return monitors()->length();
    1.89 +  }
    1.90 +
    1.91 +  static void destroy(JvmtiRawMonitor *monitor) {
    1.92 +    while (monitors()->contains(monitor)) {
    1.93 +      monitors()->remove(monitor);
    1.94 +    }
    1.95 +  }
    1.96 +
    1.97 +  // Return false if monitor is not found in the list.
    1.98 +  static bool exit(JvmtiRawMonitor *monitor) {
    1.99 +    if (monitors()->contains(monitor)) {
   1.100 +      monitors()->remove(monitor);
   1.101 +      return true;
   1.102 +    } else {
   1.103 +      return false;
   1.104 +    }
   1.105 +  }
   1.106 +
   1.107 +  static void transition_raw_monitors();
   1.108 +};
   1.109 +
   1.110 +#endif // SHARE_VM_PRIMS_JVMTIRAWMONITOR_HPP

mercurial