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. |