From: Marek P. <ma...@us...> - 2001-11-27 23:56:34
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/commun In directory usw-pr-cvs1:/tmp/cvs-serv22338/net/sourceforge/javaprofiler/jpiimpl/commun Modified Files: IProf.java Added Files: UNAVAILABLE_Exception.java Log Message: changes in interface enableGC(), disableGC(), runGC() added --- NEW FILE: UNAVAILABLE_Exception.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.commun; /** Unavailable operation exception. This exception is raised when ** an operation is not available (because of various/uknown reasons). ** ** @author Marek Przeczek */ public class UNAVAILABLE_Exception extends IProfException {}; Index: IProf.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/commun/IProf.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** IProf.java 2001/11/21 22:15:29 1.5 --- IProf.java 2001/11/27 23:56:31 1.6 *************** *** 127,131 **** --- 127,140 ---- /// remote getChanged() method identifier private static final int F_GET_CHANGED = 8; + + /// remote enableGC() method identifier + private static final int F_ENABLE_GC = 9; + + /// remote disableGC() method identifier + private static final int F_DISABLE_GC = 10; + /// remote runGC() method identifier + private static final int F_RUN_GC = 11; + /// internal I/O buffer private Buffer _buf = new Buffer(); *************** *** 204,209 **** --- 213,224 ---- } + /// indication whether threads in profiled JVM are suspended or not + private boolean _threadsSuspended = false; + /** Suspend JVM. This method suspends running profiled JVM. ** Suspended JVM can be then resumed by resumeVM() call. + ** Garbage collector of profiled JVM is disabled after this + ** call and must stay disabled until resumeVM() method is + ** called. ** ** @see resumeVM() */ *************** *** 211,216 **** public synchronized void suspendVM() ! throws COMMUN_Exception { _buf.clear(); _buf.putInt( F_SUSPEND_VM); --- 226,235 ---- public synchronized void suspendVM() ! throws COMMUN_Exception, ! UNAVAILABLE_Exception { + if( _threadsSuspended) + throw new UNAVAILABLE_Exception(); + _buf.clear(); _buf.putInt( F_SUSPEND_VM); *************** *** 219,222 **** --- 238,243 ---- if( _commun.hasFailed()) throw new COMMUN_Exception(); + _threadsSuspended = true; + _commun.read( _buf); if( _commun.hasFailed()) throw new COMMUN_Exception(); *************** *** 225,229 **** /** Resume JVM. This method resumes suspended profiled JVM. ** Resumed (running) JVM can be then suspended again ! ** by suspendVM() call. ** ** @see suspendVM() */ --- 246,252 ---- /** Resume JVM. This method resumes suspended profiled JVM. ** Resumed (running) JVM can be then suspended again ! ** by suspendVM() call. Garbage collector of profiled JVM ! ** is enabled after this call again (in case it was enabled ! ** before suspendVM() call). ** ** @see suspendVM() */ *************** *** 231,236 **** public synchronized void resumeVM() ! throws COMMUN_Exception { _buf.clear(); _buf.putInt( F_RESUME_VM); --- 254,263 ---- public synchronized void resumeVM() ! throws COMMUN_Exception, ! UNAVAILABLE_Exception { + if( !_threadsSuspended) + throw new UNAVAILABLE_Exception(); + _buf.clear(); _buf.putInt( F_RESUME_VM); *************** *** 239,246 **** --- 266,354 ---- if( _commun.hasFailed()) throw new COMMUN_Exception(); + _threadsSuspended = false; + _commun.read( _buf); if( _commun.hasFailed()) throw new COMMUN_Exception(); } + /// indication whether GC of profiled JVM is disabled or not + private int _gcDisabled = 0; + + /** Enable Java garbage collector. This method enables + ** Java garbage collector of profiled JVM. Enabling and + ** disabling of GC can be nested ! + ** + ** @see disableGC(), runGC() */ + + public synchronized void enableGC() + + throws COMMUN_Exception, + UNAVAILABLE_Exception { + + if( _threadsSuspended || _gcDisabled == 0) + throw new UNAVAILABLE_Exception(); + + _buf.clear(); + _buf.putInt( F_ENABLE_GC); + + _commun.write( _buf); + if( _commun.hasFailed()) throw new COMMUN_Exception(); + + _gcDisabled--; + + _commun.read( _buf); + if( _commun.hasFailed()) throw new COMMUN_Exception(); + } + + /** Disable Java garbage collector. This method disables + ** Java garbage collector of profiled JVM. Enabling and + ** disabling can be nested ! + ** + ** @see enableGC(), runGC() */ + + public synchronized void disableGC() + + throws COMMUN_Exception, + UNAVAILABLE_Exception { + + if( _threadsSuspended) + throw new UNAVAILABLE_Exception(); + + _buf.clear(); + _buf.putInt( F_DISABLE_GC); + + _commun.write( _buf); + if( _commun.hasFailed()) throw new COMMUN_Exception(); + + _gcDisabled++; + + _commun.read( _buf); + if( _commun.hasFailed()) throw new COMMUN_Exception(); + } + + /** Run Java garbage collector explicitly. This method runs + ** Java garbage collector inside profiled JVM. It can only + ** be called when GC is enabled. + ** + ** @see enableGC(), disableGC() */ + + public synchronized void runGC() + + throws COMMUN_Exception, + UNAVAILABLE_Exception { + + if( _threadsSuspended || _gcDisabled > 0) + throw new UNAVAILABLE_Exception(); + + _buf.clear(); + _buf.putInt( F_RUN_GC); + + _commun.write( _buf); + if( _commun.hasFailed()) throw new COMMUN_Exception(); + + _commun.read( _buf); + if( _commun.hasFailed()) throw new COMMUN_Exception(); + } + /** Exit JVM. This method exits running (or shutdowning) ** profiled JVM. Profiled JVM is stopped immediatelly. *************** *** 1282,1285 **** --- 1390,1396 ---- }; + /// constant for no optional argument in call to getAll()/getChanged() + public static final int NO_OPTIONAL_ARG = 0; + /** Internal implementation of getAll() and getChanged(). This ** method is a general implementation of getAll() and getChanged() *************** *** 1477,1481 **** UNKNOWN_Exception { ! return getChangedOrAll( F_GET_ALL, objId, seqType, false, 0); } --- 1588,1592 ---- UNKNOWN_Exception { ! return getChangedOrAll( F_GET_ALL, objId, seqType, false, NO_OPTIONAL_ARG); } *************** *** 1535,1539 **** UNKNOWN_Exception { ! return getChangedOrAll( F_GET_CHANGED, objId, seqType, false, 0); } --- 1646,1650 ---- UNKNOWN_Exception { ! return getChangedOrAll( F_GET_CHANGED, objId, seqType, false, NO_OPTIONAL_ARG); } |