📄 monitor.h
字号:
/*
* @(#)monitor.h 1.34 97/10/07
*
* Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
* CopyrightVersion 1.1_beta
*
*/
/* dfb modifications (MON_FLAT)
* 1: move MSB to high bit
* 2: parameterize monitor shape sense (SHAPE_TID/SHAPE_MID)
* 3: reverse sense of monitor shape bit (MSB)
* 4: start short count at 0 instead of 1.
* 5: inline monitorEnterQuicker, convert ATOMIC_ADD to "+"
* 6: inline monitorExitQuicker
* 7: remove multi-level macros
* 8: use inlining names compatible with asm code
* 10: pre-shifted thread index
* 11: update inlined enter/exit code: remove redundant mask, adjust countmax
*/
/*
* Monitor interface
*/
#ifndef _MONITOR_H_
#define _MONITOR_H_
#include "sys_api.h"
#ifdef MON_FLAT/* ibm.3740 */
#include "atomic_md.h"
#if !defined(IBM_OS2) && !defined(IBM_WIN32) /*ibm.5421*/
#include "../native_threads/include/monitor_md.h"
#endif
#if defined(IBM_WIN32) /*ibm.5421*/
#include "monitor_md.h"
#endif /*ibm.5421*/
#define MAKE_MASK(nbits, shift) (((1<<nbits)-1)<<shift)
#define GET_VALUE(word,mask,shift) (((word) & mask) >> shift)
#define FlatLockBits 24
#define FlatLockShift 8
#define FlatLockMask MAKE_MASK(FlatLockBits, FlatLockShift)
#define ShapeShift 31
#define ShapeMask (1<<ShapeShift)
#define MonitorBits 23
#define MonitorShift 8
#define MonitorMask MAKE_MASK(MonitorBits, MonitorShift)
#define ThreadBits 15
#define ThreadShift 16
#define ThreadMask MAKE_MASK(ThreadBits, ThreadShift)
#define CountBits 8
#define CountShift 8
#define CountMask MAKE_MASK(CountBits, CountShift)
#define CountIncrement (1<<CountShift)
#define monword(obj) (obj->locknflags)
#define monaddr(obj) (& monword(obj))
#if defined(DEBUG) || (!defined(IBM_AIX) && !defined(IBM_OS2) && !defined(IBM_4690)) /* ibm.3867 *//*ibm.8015*/
# define MONITOR_ENTER_QUICKER(obj,ee) monitorEnterQuicker(obj,ee)
# define MONITOR_EXIT_QUICKER(obj,ee) monitorExitQuicker(obj,ee)
#else /* ! DEBUG && (IBM_AIX || IBM_OS2)*/
# define MONITOR_ENTER_QUICKER(obj,ee) monitorEnterAsm(obj,ee)
# define MONITOR_EXIT_QUICKER(obj,ee) monitorExitAsm(obj,ee)
#endif
/* Test if monitor is inflated */
#define monword_inflated_p(_word) (((iatomic_t) _word) < 0)
#define monitor_inflated_p(_obj) (monword_inflated_p(monword(_obj)))
/* Test if monitor is not inflated and locked by the given thread */
#define flat_locked(_obj,__tid__) \
((monword(_obj) & (ThreadMask | ShapeMask)) == (__tid__))
/* Get the number of times we've locked this flat-locked object */
#define monitor_get_entrycount(_obj) \
(GET_VALUE(monword(_obj), CountMask, CountShift)+1)
/* Get the pointer to the inflated monitor, or NULL if it is not inflated */
#define monitor_infl(_obj) \
(! (monitor_inflated_p(_obj)) ? NULL : \
monitorIndexToMonitor(GET_VALUE(monword(_obj), MonitorMask, MonitorShift)))
/* Calculate the new monword for the object given the monitor index */
#define SET_MON_MIDX(obj, midx) \
((monword(obj) & ~FlatLockMask) | (midx << MonitorShift) | ShapeMask)
typedef struct infl_mon { /* an inflated monitor */
struct infl_mon *next;
int index;
struct sys_mon _sysmon;
} infl_mon_t, *infl_mon_id;
#else /* ibm.3740 */
/*
* Used by the monitor caching machanism to mark monitors as being
* in-use.
*/
#define MON_LOCAL_CACHE_REF (1 << 0)
/*
* The monitor data structure:
*
* The use_count field counts the number of createMonitor calls yet
* unmatched by monitorExit calls; that is, it is a count of outstanding
* monitor entries of all threads regardless of whether those threads
* own the monitor or are waiting on it.
*
* Note that because the mid[] array will hold the system-specific
* sys_mon_t, it needs to start on a four-byte boundary lest the fields
* of the sys_mon_t aren't properly aligned. Otherwise the flags field
* would be shorter than a long.
*/
typedef struct monitor_t {
unsigned int key; /* Monitor hash key */
struct monitor_t *next;
char mid[1]; /* The sys_mon_t */
} monitor_t, *MID;
/* A macro for accessing the sys_mon_t from the monitor_t */
#define sysmon(m) (*(sys_mon_t *) m->mid)
#endif /* ibm.3411 */
typedef struct reg_mon_t {
sys_mon_t *mid;
char *name;
struct reg_mon_t *next;
} reg_mon_t;
/*
* Macros
*/
#define MID_NULL ((MID) 0)
#define TIMEOUT_INFINITY -1
/*
* Support for the monitor registry
*/
extern sys_mon_t *_registry_lock;
#define REGISTRY_LOCK_INIT() monitorRegister(_registry_lock, \
"Monitor registry")
#define REGISTRY_LOCK() sysMonitorEnter(_registry_lock)
#define REGISTRY_LOCKED() sysMonitorEntered(_registry_lock)
#define REGISTRY_UNLOCK() sysMonitorExit(_registry_lock)
/*
* External routines.
*/
#ifdef MON_FLAT /* ibm.3740 */
struct Hjava_lang_Object;
struct execenv; /* ibm.3796 */
#endif
/*
* Synchronization interface
*/
void monitorCacheInit(void);
#ifdef MON_FLAT /* ibm.3740 */
void monitorDeflate(struct Hjava_lang_Object *);
void monitorEnter(struct Hjava_lang_Object *);
void monitorExit(struct Hjava_lang_Object *);
void monitorWait(struct Hjava_lang_Object *, int);
void monitorNotify(struct Hjava_lang_Object *);
void monitorNotifyAll(struct Hjava_lang_Object *);
void monitorEnterQuicker(struct Hjava_lang_Object *, struct execenv *); /* ibm.3796 */
void monitorExitQuicker(struct Hjava_lang_Object *, struct execenv *); /* ibm.3796 */
void monitorEnterAsm(struct Hjava_lang_Object *, struct execenv *); /* ibm.3796 */
void monitorExitAsm(struct Hjava_lang_Object *, struct execenv *); /* ibm.3796 */
void monitorExitError(struct Hjava_lang_Object *, struct execenv *); /* ibm.3796 */
void inflMonitorInit(infl_mon_t *);
#else
void monitorInit(monitor_t *mon);
void monitorEnter(unsigned int);
void monitorExit(unsigned int);
void monitorWait(unsigned int, int);
void monitorNotify(unsigned int);
void monitorNotifyAll(unsigned int);
#if (defined(IBM_AIX) || defined(IBM_4690)) /* ibm.3812 *//*ibm.7306*/
void monitorEnterQuicker(unsigned int, struct execenv * );
void monitorExitQuicker(unsigned int, struct execenv *);
#endif /* ibm.3812 */
#endif /* ibm.3411 */
/* Registry of static monitors */
extern reg_mon_t *MonitorRegistry;
void monitorRegistryInit(void);
void monitorRegister(sys_mon_t *, char *);
void monitorUnregister(sys_mon_t *);
void registeredEnumerate(void (*)(reg_mon_t *, void *), void *);
void registeredEnumerate_unlocked(void (*)(reg_mon_t *, void *), void *);
/*
* Random non-local locks without obviously better homes
*/
/* The class loading lock */
extern sys_mon_t *_loadclass_lock;
#define LOADCLASS_LOCK_INIT() \
monitorRegister(_loadclass_lock, "Class loading lock")
#define LOADCLASS_LOCK() sysMonitorEnter(_loadclass_lock)
#define LOADCLASS_LOCKED() sysMonitorEntered(_loadclass_lock)
#define LOADCLASS_UNLOCK() sysMonitorExit(_loadclass_lock)
/* The global class table (binclasses) lock */
extern sys_mon_t *_binclass_lock;
#define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
#define BINCLASS_LOCK() sysMonitorEnter(_binclass_lock)
#define BINCLASS_LOCKED() sysMonitorEntered(_binclass_lock)
#define BINCLASS_UNLOCK() sysMonitorExit(_binclass_lock)
/* Locks on the interned string hash table */
extern sys_mon_t *_stringhash_lock;
#define STRINGHASH_INIT() monitorRegister(_stringhash_lock, \
"String intern lock")
#define STRINGHASH_LOCK() sysMonitorEnter(_stringhash_lock)
#define STRINGHASH_LOCKED() sysMonitorEntered(_stringhash_lock)
#define STRINGHASH_UNLOCK() sysMonitorExit(_stringhash_lock)
/* Locks on the method info (name and signature) hash table */
extern sys_mon_t *_nametypehash_lock;
#define NAMETYPEHASH_INIT() monitorRegister(_nametypehash_lock, \
"Name and type hash table lock")
#define NAMETYPEHASH_LOCK() sysMonitorEnter(_nametypehash_lock)
#define NAMETYPEHASH_LOCKED() sysMonitorEntered(_nametypehash_lock)
#define NAMETYPEHASH_UNLOCK() sysMonitorExit(_nametypehash_lock)
/* JNI global reference locks */
extern sys_mon_t *_globalref_lock;
#define GLOBALREF_LOCK_INIT() \
monitorRegister(_globalref_lock, "JNI global reference lock")
#define GLOBALREF_LOCK() sysMonitorEnter(_globalref_lock)
#define GLOBALREF_LOCKED() sysMonitorEntered(_globalref_lock)
#define GLOBALREF_UNLOCK() sysMonitorExit(_globalref_lock)
#endif /* !_MONITOR_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -