From: <ls...@us...> - 2008-11-06 12:04:59
|
Revision: 4671 http://jnode.svn.sourceforge.net/jnode/?rev=4671&view=rev Author: lsantha Date: 2008-11-06 12:04:41 +0000 (Thu, 06 Nov 2008) Log Message: ----------- Fixed coding style. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/scheduler/Monitor.java trunk/core/src/core/org/jnode/vm/scheduler/MonitorManager.java Modified: trunk/core/src/core/org/jnode/vm/scheduler/Monitor.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/Monitor.java 2008-11-05 13:26:05 UTC (rev 4670) +++ trunk/core/src/core/org/jnode/vm/scheduler/Monitor.java 2008-11-06 12:04:41 UTC (rev 4671) @@ -110,6 +110,7 @@ * locked by the current thread. * * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ @Inline public final void enter() { @@ -160,6 +161,7 @@ * Giveup this monitor. * * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ public final void exit() { String exMsg = null; @@ -203,6 +205,7 @@ * * @param timeout * @throws org.vmmagic.pragma.UninterruptiblePragma + * * @throws InterruptedException */ public final void Wait(long timeout) throws InterruptedException { @@ -272,6 +275,7 @@ * Notify threads waiting on this monitor. * * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ public final void NotifyAll() { Notify(true); @@ -282,6 +286,7 @@ * * @param all * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ final void Notify(boolean all) { final VmProcessor proc = VmProcessor.current(); @@ -311,6 +316,7 @@ * exception thrown if the monitor is not locked. * * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ final boolean unsynchronizedNotifyAll() { if (lockNoWait()) { @@ -331,6 +337,7 @@ * @param thread * @return boolean * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ @Inline final boolean isOwner(VmThread thread) { @@ -354,6 +361,7 @@ * * @return boolean * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ @Inline final boolean isLocked() { @@ -368,6 +376,7 @@ * @param queueName * @return The queue * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ private final void prepareWait(VmThread thread, VmThreadQueue.ScheduleQueue queue, int waitState, String queueName) { @@ -385,6 +394,7 @@ * * @param thread * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ @NoInline private final void notifyThread(VmThread thread) { @@ -423,10 +433,10 @@ * @param queue * @param all * @throws org.vmmagic.pragma.UninterruptiblePragma + * */ @Inline - private final void wakeupWaitingThreads(VmThreadQueue.ScheduleQueue queue, - boolean all) { + private final void wakeupWaitingThreads(VmThreadQueue.ScheduleQueue queue, boolean all) { if (queue != null) { while (!queue.isEmpty()) { final VmThread thread = queue.first(); @@ -459,8 +469,7 @@ @Inline private final void lock() { //final VmProcessor proc = VmProcessor.current(); - final Address mlAddr = ObjectReference.fromObject(this).toAddress() - .add(4); + final Address mlAddr = ObjectReference.fromObject(this).toAddress().add(4); while (!mlAddr.attempt(0, 1)) { //proc.yield(true); // Yield breaks the Uninterruptible idea, so don't use it! } @@ -474,8 +483,7 @@ */ @Inline private final boolean lockNoWait() { - final Address mlAddr = ObjectReference.fromObject(this).toAddress() - .add(4); + final Address mlAddr = ObjectReference.fromObject(this).toAddress().add(4); return mlAddr.attempt(0, 1); } Modified: trunk/core/src/core/org/jnode/vm/scheduler/MonitorManager.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/MonitorManager.java 2008-11-05 13:26:05 UTC (rev 4670) +++ trunk/core/src/core/org/jnode/vm/scheduler/MonitorManager.java 2008-11-06 12:04:41 UTC (rev 4671) @@ -51,19 +51,15 @@ } // Prepare - final Word tid = Word.fromIntZeroExtend(VmMagic.currentProcessor() - .getCurrentThread().getId()); - final Address objectPtr = ObjectReference.fromObject(object) - .toAddress(); - final Address statusPtr = objectPtr.add(ObjectLayout.FLAGS_SLOT - * Address.size()); + final Word tid = Word.fromIntZeroExtend(VmMagic.currentProcessor().getCurrentThread().getId()); + final Address objectPtr = ObjectReference.fromObject(object).toAddress(); + final Address statusPtr = objectPtr.add(ObjectLayout.FLAGS_SLOT * Address.size()); for (;;) { // attempt fast path: object is not locked. final Word oldlockword = statusPtr.prepareWord(); - final Word statusFlags = oldlockword.and(Word - .fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK)); + final Word statusFlags = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK)); if (statusPtr.attempt(statusFlags, statusFlags.or(tid))) { // fast path succeeded, the object was not locked and // has been locked by the current thread. @@ -71,19 +67,15 @@ } // object is locked or has an inflated lock. - if (!oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { + if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { // slow path 2: high bit of lock word is set --> inflated lock final Monitor m = getMonitor(oldlockword); m.enter(); return; - } else if (oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid)) { + } else if (oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid)) { // Current thread owns the thinlock - final Word counter = oldlockword.and(Word - .fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)); - if (counter.EQ(Word - .fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK))) { + final Word counter = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)); + if (counter.EQ(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK))) { // thin lock entry counter == max, so we need to inflate // ourselves. installInflatedLock(object).enter(); @@ -95,8 +87,7 @@ // thread, so // be cautious final Word newlockword; - newlockword = oldlockword.add(Word - .fromIntZeroExtend(ObjectFlags.LOCK_COUNT_INC)); + newlockword = oldlockword.add(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_INC)); // Try to update lock, it may be inflated by some other // thread, so // be cautious @@ -128,12 +119,9 @@ } // Prepare - final Word tid = Word.fromIntZeroExtend(VmMagic.currentProcessor() - .getCurrentThread().getId()); - final Address objectPtr = ObjectReference.fromObject(object) - .toAddress(); - final Address statusPtr = objectPtr.add(ObjectLayout.FLAGS_SLOT - * Address.size()); + final Word tid = Word.fromIntZeroExtend(VmMagic.currentProcessor().getCurrentThread().getId()); + final Address objectPtr = ObjectReference.fromObject(object).toAddress(); + final Address statusPtr = objectPtr.add(ObjectLayout.FLAGS_SLOT * Address.size()); for (;;) { final Word oldlockword = statusPtr.prepareWord(); @@ -144,26 +132,21 @@ // if not inflated and tid matches, this contains status flags and // counter - if (!oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { + if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { // inflated lock final Monitor m = getMonitor(oldlockword); m.exit(); return; - } else if (oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid)) { + } else if (oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid)) { // owned by current thread - final Word counter = oldlockword.and(Word - .fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)); + final Word counter = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)); final Word newlockword; if (counter.isZero()) { // Count is zero, clear tid field - newlockword = oldlockword.and(Word - .fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK)); + newlockword = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK)); } else { // count is non-zero, decrement count - newlockword = oldlockword.sub(Word - .fromIntSignExtend(ObjectFlags.LOCK_COUNT_INC)); + newlockword = oldlockword.sub(Word.fromIntSignExtend(ObjectFlags.LOCK_COUNT_INC)); } if (statusPtr.attempt(oldlockword, newlockword)) { return; @@ -178,14 +161,11 @@ Unsafe.debug(oldlockword); Unsafe.debug(objectPtr); Unsafe.debug(statusPtr); - Unsafe.debug(oldlockword.and(Word - .fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK))); + Unsafe.debug(oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK))); Unsafe.debug(tid); Unsafe.debug(statusPtr.prepareWord()); - VmMagic.currentProcessor().getArchitecture().getStackReader() - .debugStackTrace(); - Unsafe - .die("Please report this problem with the above values to ep...@jn..."); + VmMagic.currentProcessor().getArchitecture().getStackReader().debugStackTrace(); + Unsafe.die("Please report this problem with the above values to ep...@jn..."); throw new IllegalMonitorStateException(exMsg); } } @@ -198,8 +178,7 @@ * @param timeout * @throws InterruptedException */ - public static void wait(Object object, long timeout) - throws InterruptedException { + public static void wait(Object object, long timeout) throws InterruptedException { // Test interrupted state of current thread if (VmThread.currentThread().isInterrupted(true)) { throw new InterruptedException(); @@ -261,50 +240,41 @@ * Installs an inflated lock on the given object. Uses a spin-loop to wait * until the object is unlocked or inflated. * - * @param k - * @param m - * @param slotSize + * @param k the object for which the inflated lock is installed + * @return the Monitor object representing the lock */ private static Monitor installInflatedLock(Object k) { Monitor m = null; Word monAddr = null; final Address kPtr = ObjectReference.fromObject(k).toAddress(); - final Address statusPtr = kPtr.add(ObjectLayout.FLAGS_SLOT - * Address.size()); + final Address statusPtr = kPtr.add(ObjectLayout.FLAGS_SLOT * Address.size()); for (;;) { final Word oldlockword = statusPtr.prepareWord(); - if (!oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { + if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { // inflated by another thread, use that one. return getMonitor(oldlockword); } if (m == null) { - m = new Monitor(VmMagic.currentProcessor().getCurrentThread(), - 1); + m = new Monitor(VmMagic.currentProcessor().getCurrentThread(), 1); monAddr = ObjectReference.fromObject(m).toAddress().toWord(); - if (!monAddr.and( - Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED - | ObjectFlags.STATUS_FLAGS_MASK)).isZero()) { - throw new InternalError( - "Monitor object has address that conflicts with header flags 0x" - + NumberUtils.hex(monAddr.toInt())); + if (!monAddr.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED + | ObjectFlags.STATUS_FLAGS_MASK)).isZero()) { + throw new InternalError("Monitor object has address that conflicts with header flags 0x" + + NumberUtils.hex(monAddr.toInt())); } } // Put entry count & owner in monitor - int lockcount = 1 + oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)).rshl(ObjectFlags.LOCK_COUNT_SHIFT).toInt(); - int ownerId = oldlockword.and( - Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).toInt(); + int lockcount = 1 + oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)). + rshl(ObjectFlags.LOCK_COUNT_SHIFT).toInt(); + int ownerId = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).toInt(); m.initialize(VmMagic.currentProcessor().getScheduler().getThreadById(ownerId), lockcount); - final Word statusFlags = oldlockword.and(Word - .fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK)); - final Word newlockword = monAddr.or(statusFlags).or( - Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)); + final Word statusFlags = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK)); + final Word newlockword = monAddr.or(statusFlags).or(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)); if (statusPtr.attempt(oldlockword, newlockword)) { // successfully obtained inflated lock. return m; @@ -319,11 +289,8 @@ * @return The monitor */ private static Monitor getMonitor(Word lockword) { - final Address address = lockword - .and( - Word - .fromIntZeroExtend(~(ObjectFlags.LOCK_EXPANDED | ObjectFlags.STATUS_FLAGS_MASK))) - .toAddress(); + final Address address = lockword.and(Word.fromIntZeroExtend( + ~(ObjectFlags.LOCK_EXPANDED | ObjectFlags.STATUS_FLAGS_MASK))).toAddress(); if (address.isZero()) { String exMsg = "Inflated monitor is null????"; @@ -342,11 +309,10 @@ */ @Internal public static Monitor getInflatedMonitor(Object object) { - final Word oldlockword = ObjectReference.fromObject(object).toAddress() - .add(ObjectLayout.FLAGS_SLOT * Address.size()).loadWord(); + final Word oldlockword = ObjectReference.fromObject(object).toAddress(). + add(ObjectLayout.FLAGS_SLOT * Address.size()).loadWord(); - if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)) - .isZero()) { + if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { return getMonitor(oldlockword); } else { return null; @@ -365,16 +331,14 @@ public static boolean holdsLock(Object obj) { final VmThread current = VmThread.currentThread(); - final Word lockword = ObjectReference.fromObject(obj).toAddress().add( - ObjectLayout.FLAGS_SLOT * Address.size()).prepareWord(); + final Word lockword = ObjectReference.fromObject(obj).toAddress(). + add(ObjectLayout.FLAGS_SLOT * Address.size()).prepareWord(); - if (!lockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)) - .isZero()) { + if (!lockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) { return getMonitor(lockword).isOwner(current); } else { final Word tid = Word.fromIntZeroExtend(current.getId()); - return lockword.and( - Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid); + return lockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2009-08-16 13:47:53
|
Revision: 5652 http://jnode.svn.sourceforge.net/jnode/?rev=5652&view=rev Author: fduminy Date: 2009-08-16 13:47:45 +0000 (Sun, 16 Aug 2009) Log Message: ----------- fixed comments & warnings in javadoc Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java Modified: trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2009-08-16 11:48:25 UTC (rev 5651) +++ trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2009-08-16 13:47:45 UTC (rev 5652) @@ -64,27 +64,27 @@ private volatile Word threadSwitchIndicator; /** - * Reference to myself; used in assembly code + * Reference to myself; used in assembly code. */ final VmProcessor me; /** - * The current thread on this processor + * The current thread on this processor. */ protected volatile VmThread currentThread; /** - * The isolated statics table of the current thread (int[]) + * The isolated statics table of the current thread (int[]). */ private volatile Object isolatedStaticsTable; /** - * The isolated statics table of the current thread + * The isolated statics table of the current thread. */ private volatile VmIsolatedStatics isolatedStatics; /** - * The next thread to schedule on this processor + * The next thread to schedule on this processor. */ volatile VmThread nextThread; @@ -99,54 +99,54 @@ protected volatile Address kernelStackEnd; /** - * The identifier of this processor + * The identifier of this processor. */ private int id; /** - * The identifier of this processor as string + * The identifier of this processor as string. */ private String idString; /** - * IRQ manager for this processor + * IRQ manager for this processor. */ private IRQManager irqMgr; /** - * Address of threadSwitchIndicator + * Address of threadSwitchIndicator. */ private Address tsiAddress; /** - * The scheduler that is used + * The scheduler that is used. */ private final VmScheduler scheduler; /** - * The architecture of this processor + * The architecture of this processor. */ private final VmArchitecture architecture; /** - * The idle thread + * The idle thread. */ private IdleThread idleThread; private int lockCount; /** - * CPU identification + * CPU identification. */ private transient CpuID cpuId; /** - * The statics table (int[]) + * The statics table (int[]). */ private volatile Object staticsTable; /** - * The processor speed indication + * The processor speed indication. */ private float jnodeMips; @@ -155,12 +155,12 @@ private int sameThreadPriorityCount; /** - * The data specific to this processor used by the heap manager + * The data specific to this processor used by the heap manager. */ private final Object heapData; /** - * Per processor MathSupport memory structures + * Per processor MathSupport memory structures. */ private final MathSupport mathSupport = new MathSupport(); @@ -177,27 +177,27 @@ private final int[] compilerIds; /** - * Indicate the a thread switch is needed + * Indicate the a thread switch is needed. */ public static final int TSI_SWITCH_NEEDED = 0x0001; /** - * Indicate that the system is ready for thread switching + * Indicate that the system is ready for thread switching. */ public static final int TSI_SYSTEM_READY = 0x0002; /** - * Indicate the a thread switch is in progress + * Indicate the a thread switch is in progress. */ public static final int TSI_SWITCH_ACTIVE = 0x0004; /** - * Indicate the a thread switch cannot occur + * Indicate the a thread switch cannot occur. */ public static final int TSI_BLOCK_SWITCH = 0x0008; /** - * Indicate the a thread switch is requested + * Indicate the a thread switch is requested. */ public static final int TSI_SWITCH_REQUESTED = TSI_SWITCH_NEEDED | TSI_SYSTEM_READY; @@ -215,7 +215,7 @@ } /** - * Initialize this instance + * Initialize this instance. * * @param id * @param architecture @@ -256,7 +256,7 @@ } /** - * Gets the current thread on this processor + * Gets the current thread on this processor. * * @return The current thread on this processor * @throws org.vmmagic.pragma.UninterruptiblePragma @@ -298,7 +298,7 @@ } /** - * Create an ID string for the given id + * Create an ID string for the given id. * * @param id * @return the ID string @@ -501,14 +501,14 @@ } /** - * Create a new thread + * Create a new thread. * * @return The new thread */ protected abstract VmThread createThread(VmIsolatedStatics isolatedStatics); /** - * Create a new thread + * Create a new thread. * * @param javaThread * @return The new thread @@ -518,7 +518,7 @@ } /** - * Create a new thread + * Create a new thread. * * @param javaThread * @return The new thread @@ -536,7 +536,7 @@ protected abstract int[] getIrqCounters(); /** - * Mark the system are ready for thread switching + * Mark the system as ready for thread switching. */ @Internal public final void systemReadyForThreadSwitch() { @@ -548,8 +548,8 @@ } /** - * Gets the address of the threadSwitchIndicator field in this object. It is - * assumed the this field is the first field of this class! + * Gets the address of the threadSwitchIndicator field in this object. <b>It is + * assumed this field is the first field of this class!</b> * * @return The address of the thread switch indicator */ @@ -590,7 +590,7 @@ /** * Load the CPU id. * - * @param id The idenfication returned by Unsafe.getCpuID + * @param id The identification returned by Unsafe.getCpuID * @return CpuID */ protected abstract CpuID loadCPUID(int[] id); @@ -630,7 +630,7 @@ } /** - * Calculate the processor speed and delay loops. + * Calculate the processor speed in "JNodeMips" and delay loops. */ @Internal public final void calibrate() { @@ -643,7 +643,7 @@ /** * Gets the processor speed indication. * - * @return the notional processor speed. + * @return the processor speed in "JNodeMips". */ public final float getJNodeMips() { return jnodeMips; Modified: trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java 2009-08-16 11:48:25 UTC (rev 5651) +++ trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java 2009-08-16 13:47:45 UTC (rev 5652) @@ -43,32 +43,32 @@ public final class VmScheduler { /** - * Reference to current architecture + * Reference to current architecture. */ private final VmArchitecture architecture; /** - * Lock for the allThreadsQueue + * Lock for the allThreadsQueue. */ private final ProcessorLock allThreadsLock; /** - * Queue holding all threads + * Queue holding all threads. */ private final VmThreadQueue.AllThreadsQueue allThreadsQueue; /** - * My ready queue + * My ready queue. */ private final VmThreadQueue.ScheduleQueue readyQueue; /** - * My sleep queue + * My sleep queue. */ private final VmThreadQueue.SleepQueue sleepQueue; /** - * Lock used to protect the ready and sleep queue + * Lock used to protect the ready and sleep queue. */ private final ProcessorLock queueLock; @@ -196,7 +196,7 @@ /** * Add the given thread to the ready queue to the scheduler and remove it - * from the sleep queue (if it still was on the sleep queue) + * from the sleep queue (if it still was on the sleep queue). * * @param thread * @param ignorePriority If true, the thread is always added to the back of the list, @@ -437,7 +437,7 @@ } /** - * Unlock the queues + * Unlock the queues. */ @Inline @Uninterruptible This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2009-08-16 14:27:01
|
Revision: 5653 http://jnode.svn.sourceforge.net/jnode/?rev=5653&view=rev Author: fduminy Date: 2009-08-16 14:26:53 +0000 (Sun, 16 Aug 2009) Log Message: ----------- moved kernel debugger (kdb) stuff from VmScheduler to its own class : KernelDebugger Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java Added Paths: ----------- trunk/core/src/core/org/jnode/vm/scheduler/KernelDebugger.java Added: trunk/core/src/core/org/jnode/vm/scheduler/KernelDebugger.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/KernelDebugger.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/scheduler/KernelDebugger.java 2009-08-16 14:26:53 UTC (rev 5653) @@ -0,0 +1,217 @@ +/* + * $Id: VmProcessor.java 5226 2009-04-06 14:55:27Z lsantha $ + * + * Copyright (C) 2003-2009 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.vm.scheduler; + +import org.jnode.annotation.Inline; +import org.jnode.annotation.KernelSpace; +import org.jnode.annotation.Uninterruptible; +import org.jnode.vm.LoadCompileService; +import org.jnode.vm.Unsafe; +import org.jnode.vm.VmMagic; +import org.jnode.vm.VmStackReader; + +/** + * This is the Kernel Debugger (also known as kdb). + * + * @author Ewout Prangsma (ep...@us...) + * @author Fabien DUMINY (fd...@jn...) + * + */ +public class KernelDebugger { + private final VmScheduler vmScheduler; + + KernelDebugger(VmScheduler vmScheduler) { + this.vmScheduler = vmScheduler; + } + + /** + * Process all waiting KDB commands. + */ + @Uninterruptible + @KernelSpace + @Inline + final void processAllKdbInput() { + int ch; + while ((ch = readKdbInput()) >= 0) { + processKdbInput(ch); + } + } + + /** + * Process the input from the kernel debugger. + * + * @param input + * @throws org.vmmagic.pragma.UninterruptiblePragma + */ + @Uninterruptible + @KernelSpace + private final void processKdbInput(int input) { + switch ((char) input) { + case '?': + case 'h': + debug("Commands:\n"); + debug("l Show Load/Compile queue\n"); + debug("p Ping\n"); + debug("q Print thread queues\n"); + debug("r Print stacktraces of ready-queue\n"); + debug("t Print current thread\n"); + debug("v Verify thread\n"); + debug("w Print waiting threads\n"); + debug("W Print stacktraces of waiting threads\n"); + break; + case 'l': + debug("<load-compile-service: "); + debug("\n"); + LoadCompileService.showInfo(); + debug("/>\n"); + break; + case 'p': + debug("<ping/>"); + break; + case 'q': { + final VmThread currentThread = VmMagic.currentProcessor().currentThread; + debug("<queues: current-thread name='"); + debug(currentThread.getName()); + debug("' state='"); + debug(currentThread.getThreadStateName()); + debug("\n"); + vmScheduler.getReadyQueue().dump(false, null); + vmScheduler.getSleepQueue().dump(false, null); + debug("/>\n"); + break; + } + case 'r': + debug("<traces: "); + debug("\n"); + vmScheduler.getReadyQueue().dump(true, vmScheduler.getStackReader()); + debug("/>\n"); + break; + case 'v': + debug("<verify: "); + debug("\n"); + verifyThreads(); + debug("/>\n"); + break; + case 'w': + debug("<waiting: "); + debug("\n"); + dumpWaitingThreads(false, null); + debug("/>\n"); + break; + case 'W': + debug("<waiting: "); + debug("\n"); + dumpWaitingThreads(true, vmScheduler.getStackReader()); + debug("/>\n"); + break; + case 't': { + final VmThread currentThread = VmMagic.currentProcessor().currentThread; + debug("<currentthread name='"); + debug(currentThread.getName()); + debug("' state='"); + debug(currentThread.getThreadStateName()); + debug("'/>\n"); + break; + } + case 'T': { + final VmThread currentThread = VmMagic.currentProcessor().currentThread; + debug("<currentthread name='"); + debug(currentThread.getName()); + debug("' state='"); + debug(currentThread.getThreadStateName()); + vmScheduler.getStackReader().debugStackTrace(currentThread); + debug("'/>\n"); + break; + } + case '#': + debug("Halt for ever\n"); + while (true) + ; + + // default: + // debug(input); + } + } + + /** + * Dump the status of this queue on debug. + */ + @KernelSpace + private final void dumpWaitingThreads(boolean dumpStack, VmStackReader stackReader) { + VmThreadQueueEntry e = vmScheduler.getAllThreadsQueue().first; + while (e != null) { + if (e.thread.isWaiting()) { + debug(e.thread.getName()); + debug(" id0x"); + debug(e.thread.getId()); + debug(" s0x"); + debug(e.thread.getThreadState()); + debug(" p0x"); + debug(e.thread.priority); + debug(" wf:"); + VmThread waitFor = e.thread.getWaitForThread(); + debug((waitFor != null) ? waitFor.getName() : "none"); + debug("\n"); + if (dumpStack && (stackReader != null)) { + stackReader.debugStackTrace(e.thread); + debug("\n"); + } + } + e = e.next; + } + } + + /** + * Dump the status of this queue on debug. + */ + @KernelSpace + private final void verifyThreads() { + VmThreadQueueEntry e = vmScheduler.getAllThreadsQueue().first; + while (e != null) { + e.thread.verifyState(); + e = e.next; + } + } + + /** + * Print the given string to the output. + */ + @Inline + private final void debug(String str) { + Unsafe.debug(str); + } + + /** + * Print the given integer to the output. + */ + @Inline + private final void debug(int i) { + Unsafe.debug(i); + } + + /** + * Read a keystroke from the input. + */ + @Inline + private final int readKdbInput() { + return Unsafe.readKdbInput(); + } +} Modified: trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2009-08-16 13:47:45 UTC (rev 5652) +++ trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2009-08-16 14:26:53 UTC (rev 5653) @@ -124,6 +124,11 @@ private final VmScheduler scheduler; /** + * The kernel debugger that is used. + */ + private final KernelDebugger kernelDebugger; + + /** * The architecture of this processor. */ private final VmArchitecture architecture; @@ -228,6 +233,7 @@ this.me = this; this.architecture = architecture; this.scheduler = scheduler; + this.kernelDebugger = new KernelDebugger(scheduler); this.staticsTable = sharedStatics.getTable(); this.isolatedStatics = isolatedStatics; this.isolatedStaticsTable = isolatedStatics.getTable(); @@ -431,7 +437,7 @@ // Process kernel debugger data if (Unsafe.isKdbEnabled()) { - scheduler.processAllKdbInput(); + kernelDebugger.processAllKdbInput(); } // Dispatch interrupts if we already have an IRQ manager. Modified: trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java 2009-08-16 13:47:45 UTC (rev 5652) +++ trunk/core/src/core/org/jnode/vm/scheduler/VmScheduler.java 2009-08-16 14:26:53 UTC (rev 5653) @@ -20,18 +20,17 @@ package org.jnode.vm.scheduler; -import org.jnode.vm.LoadCompileService; +import org.jnode.annotation.Inline; +import org.jnode.annotation.Internal; +import org.jnode.annotation.KernelSpace; +import org.jnode.annotation.MagicPermission; +import org.jnode.annotation.Uninterruptible; import org.jnode.vm.Unsafe; import org.jnode.vm.Vm; import org.jnode.vm.VmArchitecture; import org.jnode.vm.VmMagic; import org.jnode.vm.VmStackReader; import org.jnode.vm.VmSystem; -import org.jnode.annotation.Inline; -import org.jnode.annotation.Internal; -import org.jnode.annotation.KernelSpace; -import org.jnode.annotation.MagicPermission; -import org.jnode.annotation.Uninterruptible; /** * Thread scheduler. This scheduler is used by all processors in the system, so @@ -104,18 +103,6 @@ } /** - * Dump the status of this queue on Unsafe.debug. - */ - @KernelSpace - final void verifyThreads() { - VmThreadQueueEntry e = allThreadsQueue.first; - while (e != null) { - e.thread.verifyState(); - e = e.next; - } - } - - /** * Register a thread in the list of all live threads. * * @param thread @@ -167,34 +154,6 @@ } /** - * Dump the status of this queue on Unsafe.debug. - */ - @KernelSpace - final void dumpWaitingThreads(boolean dumpStack, VmStackReader stackReader) { - VmThreadQueueEntry e = allThreadsQueue.first; - while (e != null) { - if (e.thread.isWaiting()) { - Unsafe.debug(e.thread.getName()); - Unsafe.debug(" id0x"); - Unsafe.debug(e.thread.getId()); - Unsafe.debug(" s0x"); - Unsafe.debug(e.thread.getThreadState()); - Unsafe.debug(" p0x"); - Unsafe.debug(e.thread.priority); - Unsafe.debug(" wf:"); - VmThread waitFor = e.thread.getWaitForThread(); - Unsafe.debug((waitFor != null) ? waitFor.getName() : "none"); - Unsafe.debug("\n"); - if (dumpStack && (stackReader != null)) { - stackReader.debugStackTrace(e.thread); - Unsafe.debug("\n"); - } - } - e = e.next; - } - } - - /** * Add the given thread to the ready queue to the scheduler and remove it * from the sleep queue (if it still was on the sleep queue). * @@ -319,129 +278,52 @@ } /** - * Process all waiting KDB commands. + * Lock the queues for access by the current processor. */ - @Uninterruptible - @KernelSpace @Inline - final void processAllKdbInput() { - int ch; - while ((ch = Unsafe.readKdbInput()) >= 0) { - processKdbInput(ch); - } + @Uninterruptible + final void lock() { + queueLock.lock(); } /** - * Process the input from the kernel debugger. - * - * @param input - * @throws org.vmmagic.pragma.UninterruptiblePragma + * Unlock the queues. */ + @Inline @Uninterruptible - @KernelSpace - private final void processKdbInput(int input) { - switch ((char) input) { - case '?': - case 'h': - Unsafe.debug("Commands:\n"); - Unsafe.debug("l Show Load/Compile queue\n"); - Unsafe.debug("p Ping\n"); - Unsafe.debug("q Print thread queues\n"); - Unsafe.debug("r Print stacktraces of ready-queue\n"); - Unsafe.debug("t Print current thread\n"); - Unsafe.debug("v Verify thread\n"); - Unsafe.debug("w Print waiting threads\n"); - Unsafe.debug("W Print stacktraces of waiting threads\n"); - break; - case 'l': - Unsafe.debug("<load-compile-service: "); - Unsafe.debug("\n"); - LoadCompileService.showInfo(); - Unsafe.debug("/>\n"); - break; - case 'p': - Unsafe.debug("<ping/>"); - break; - case 'q': { - final VmThread currentThread = VmMagic.currentProcessor().currentThread; - Unsafe.debug("<queues: current-thread name='"); - Unsafe.debug(currentThread.getName()); - Unsafe.debug("' state='"); - Unsafe.debug(currentThread.getThreadStateName()); - Unsafe.debug("\n"); - readyQueue.dump(false, null); - sleepQueue.dump(false, null); - Unsafe.debug("/>\n"); - break; - } - case 'r': - Unsafe.debug("<traces: "); - Unsafe.debug("\n"); - readyQueue.dump(true, architecture.getStackReader()); - Unsafe.debug("/>\n"); - break; - case 'v': - Unsafe.debug("<verify: "); - Unsafe.debug("\n"); - verifyThreads(); - Unsafe.debug("/>\n"); - break; - case 'w': - Unsafe.debug("<waiting: "); - Unsafe.debug("\n"); - dumpWaitingThreads(false, null); - Unsafe.debug("/>\n"); - break; - case 'W': - Unsafe.debug("<waiting: "); - Unsafe.debug("\n"); - dumpWaitingThreads(true, architecture.getStackReader()); - Unsafe.debug("/>\n"); - break; - case 't': { - final VmThread currentThread = VmMagic.currentProcessor().currentThread; - Unsafe.debug("<currentthread name='"); - Unsafe.debug(currentThread.getName()); - Unsafe.debug("' state='"); - Unsafe.debug(currentThread.getThreadStateName()); - Unsafe.debug("'/>\n"); - break; - } - case 'T': { - final VmThread currentThread = VmMagic.currentProcessor().currentThread; - Unsafe.debug("<currentthread name='"); - Unsafe.debug(currentThread.getName()); - Unsafe.debug("' state='"); - Unsafe.debug(currentThread.getThreadStateName()); - architecture.getStackReader().debugStackTrace(currentThread); - Unsafe.debug("'/>\n"); - break; - } - case '#': - Unsafe.debug("Halt for ever\n"); - while (true) - ; + final void unlock() { + queueLock.unlock(); + } - // default: - // Unsafe.debug(input); - } + /** + * @return The queue containing all ready threads. + */ + @Inline + final VmThreadQueue.ScheduleQueue getReadyQueue() { + return readyQueue; } /** - * Lock the queues for access by the current processor. + * @return The queue containing all sleeping threads. */ @Inline - @Uninterruptible - final void lock() { - queueLock.lock(); + final VmThreadQueue.SleepQueue getSleepQueue() { + return sleepQueue; } /** - * Unlock the queues. + * @return The queue containing all threads. */ @Inline - @Uninterruptible - final void unlock() { - queueLock.unlock(); + final VmThreadQueue.AllThreadsQueue getAllThreadsQueue() { + return allThreadsQueue; } + + /** + * @return The {@link VmStackReader} from the current architecture. + */ + @Inline + final VmStackReader getStackReader() { + return architecture.getStackReader(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |