harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r480141 [9/38] - in /harmony/enhanced/jdktools/trunk/modules/jpda: ./ doc/ doc/images/ make/ src/ src/common/ src/common/other/ src/common/other/jpda/ src/common/other/jpda/jdwp/ src/common/other/jpda/jdwp/agent/ src/common/other/jpda/jdwp/...
Date Tue, 28 Nov 2006 17:49:31 GMT
Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandDispatcher.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandDispatcher.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandDispatcher.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandDispatcher.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5.2.1 $
+ */
+
+/**
+ * @file
+ * CommandDispatcher.h
+ *
+ */
+
+#ifndef _COMMAD_DISPATCHER_H_
+#define _COMMAD_DISPATCHER_H_
+
+#include "AgentBase.h"
+
+namespace jdwp {
+
+    class CommandParser;
+    class CommandHandler;
+
+    /**
+     * Identifies a command passed by <code>PacketDispatcher</code>, finds
+     * an appropriate <code>CommandHandler</code> and starts execution of the
+     * given command.
+     * After getting the JDWP command from <code>PacketDispatcher</code>,
+     * <code>CommandDispatcher</code> starts an appropriate
+     * <code>CommandHandler</code>. If any errors occur while starting
+     * <code>CommandHandler</code>, <code>CommandDispatcher</code>
+     * composes and sends a reply and returns
+     * the control to <code>PacketDispatcher</code>.
+     *
+     * @see PacketDispatcher
+     * @see CommandHandler
+     */
+    class CommandDispatcher : public AgentBase
+    {
+    public:
+
+        /**
+         * Creates an object of the <code>CommandHandler</code> class according
+         * to the obtained JDWP command.
+         * The method extracts <code>jdwpCommandSet</code> and
+         * <code>jdwpCommand</code> from the <code>cmdParser</code> parameter
+         * and creates the proper <code>CommandHandler</code>, based on the current 
+         * values.
+         * Then the given handler is started.
+         *
+         * @param jni       - the JNI interface pointer
+         * @param cmdParser - a wrapper of the JDWP command to be executed
+         *
+         * @exception If a transport error occurs, <code>TransportException</code>
+         *            is thrown.
+         *
+         * @see CommandParser
+         */
+        void ExecCommand(JNIEnv* jni, CommandParser *cmdParser)
+            throw(AgentException);
+
+        /**
+         * Returns the name corresponding to the given JDWP command set.
+         *
+         * @param cmdSet - command set identifier
+         *
+         * @return Zero terminated string.
+         */
+        static const char* GetCommandSetName(jdwpCommandSet cmdSet);
+
+        /**
+         * Returns the name corresponding to the specific command of the 
+         * given JDWP command set.
+         *
+         * @param cmdSet  - command set identifier
+         * @param cmdKind - command kind
+         *
+         * @return Zero terminated string.
+         */
+        static const char* GetCommandName(jdwpCommandSet cmdSet, jdwpCommand cmdKind);
+
+    private:
+
+        static CommandHandler* CreateCommandHandler(jdwpCommandSet cmdSet, jdwpCommand cmdKind)
+            throw (NotImplementedException, OutOfMemoryException);
+
+    };//class CommandDispatcher
+
+}//namespace jdwp
+
+#endif //_COMMAD_DISPATCHER_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandDispatcher.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,295 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin, Viacheslav G. Rybalov
+ * @version $Revision: 1.18 $
+ */
+
+#include "CommandHandler.h"
+#include "PacketParser.h"
+#include "ThreadManager.h"
+#include "EventDispatcher.h"
+
+using namespace jdwp;
+
+//-----------------------------------------------------------------------------
+
+void CommandHandler::ComposeError(const AgentException &e)
+{
+    m_cmdParser->reply.SetError(e.ErrCode());
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+void SyncCommandHandler::Run(JNIEnv *jni_env, CommandParser *cmd) throw(AgentException)
+{
+    JDWP_TRACE_ENTRY("Sync::Run(" << jni_env << ',' << cmd << ')');
+
+    m_cmdParser = cmd;
+    try
+    {
+        Execute(jni_env);
+    }
+    catch (const AgentException& e)
+    {
+        ComposeError(e);
+    }
+    
+    if (cmd->reply.IsPacketInitialized())
+    {
+        cmd->WriteReply(jni_env);
+    }
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+AsyncCommandHandler::~AsyncCommandHandler()
+{
+    if (m_cmdParser != 0)
+        delete m_cmdParser;
+}
+
+//-----------------------------------------------------------------------------
+
+const char* AsyncCommandHandler::GetThreadName() {
+    return "_jdwp_AsyncCommandHandler";
+}
+
+//-----------------------------------------------------------------------------
+
+void AsyncCommandHandler::Run(JNIEnv *jni_env, CommandParser *cmd) throw(AgentException)
+{
+    JDWP_TRACE_ENTRY("Async::Run(" << jni_env << ',' << cmd << ')');
+
+    m_cmdParser = new CommandParser();
+    cmd->MoveData(jni_env, m_cmdParser);
+    try
+    {
+        GetThreadManager().RunAgentThread(jni_env, StartExecution, this,
+            JVMTI_THREAD_MAX_PRIORITY, GetThreadName());
+    }
+    catch (const AgentException& e)
+    {
+        JDWP_ASSERT(e.ErrCode() != JDWP_ERROR_NULL_POINTER);
+        JDWP_ASSERT(e.ErrCode() != JDWP_ERROR_INVALID_PRIORITY);
+
+        throw e;
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+void JNICALL
+AsyncCommandHandler::StartExecution(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
+{
+    JDWP_TRACE_ENTRY("Async::StartExecution(" << jvmti_env << ',' << jni_env << ',' << arg << ')');
+
+    AsyncCommandHandler *handler = reinterpret_cast<AsyncCommandHandler *>(arg);
+
+    try 
+    {
+        handler->Execute(jni_env);
+    }
+    catch (const AgentException &e)
+    {
+        handler->ComposeError(e);
+    }
+
+    try {
+        if (handler->m_cmdParser->reply.IsPacketInitialized())
+        {
+            JDWP_TRACE_CMD("send reply");
+            handler->m_cmdParser->WriteReply(jni_env);
+        }
+
+        JDWP_TRACE_CMD("Removing command handler: "
+            << handler->m_cmdParser->command.GetCommandSet() << "/"
+            << handler->m_cmdParser->command.GetCommand());
+
+        handler->Destroy();
+    
+    } catch (const AgentException &e) {
+        // cannot report error in async thread, just print warning message
+        JDWP_INFO("JDWP error in asynchronous command: " << e.what() << " [" << e.ErrCode() << "]");
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+SpecialAsyncCommandHandler::SpecialAsyncCommandHandler()
+{
+//    m_monitor = new AgentMonitor("SpecialAsyncCommandHandler monitor");
+    m_isInvoked = false;
+    m_isReleased = false;
+}
+
+SpecialAsyncCommandHandler::~SpecialAsyncCommandHandler()
+{
+}
+
+void SpecialAsyncCommandHandler::ExecuteDeferredInvoke(JNIEnv *jni)
+{
+    JDWP_TRACE_ENTRY("Async::ExecuteDeferredInvoke(" << jni << ')');
+    ExecuteDeferredFunc(jni);
+}
+
+void SpecialAsyncCommandHandler::WaitDeferredInvocation(JNIEnv *jni)
+{
+    JDWP_TRACE_ENTRY("Async::WaitDeferredInvocation(" << jni << ')');
+
+    GetThreadManager().RegisterInvokeHandler(jni, this);
+    GetEventDispatcher().PostInvokeSuspend(jni, this);
+}
+
+//-----------------------------------------------------------------------------
+
+jint SpecialAsyncCommandHandler::getArgsNumber(char* sig)
+{
+    if (sig == 0) return 0;
+
+    jint argsCount = 0;
+    const size_t len = strlen(sig);
+    for (size_t i = 1; i < len && sig[i] != ')'; i++) {
+        while (i < len && sig[i] == '[') i++;
+        if (sig[i] == 'L') {
+            while (i < len && sig[i] != ';' && sig[i] != ')') i++;
+        }
+        argsCount++;
+    }
+    JDWP_TRACE_CMD("sig=" << sig << "(args=" << argsCount);
+
+    return argsCount;
+}
+
+jdwpTag SpecialAsyncCommandHandler::getTag(jint index, char* sig)
+{
+    if (sig == 0) return JDWP_TAG_NONE;
+
+    const size_t len = strlen(sig);
+    size_t i;
+    for (i = 1; index > 0 && i < len && sig[i] != ')'; i++) {
+        while (i < len && sig[i] == '[') i++;
+        if (sig[i] == 'L') {
+            while (i < len && sig[i] != ';' && sig[i] != ')') i++;
+        }
+        index--;
+    }
+
+    return (index == 0) ? static_cast<jdwpTag>(sig[i]) : JDWP_TAG_NONE;
+}
+
+bool SpecialAsyncCommandHandler::getClassNameArg(jint index, char* sig, char* name)
+{
+    if (sig == 0) return false;
+
+    const size_t len = strlen(sig);
+    size_t i;
+    for (i = 1; index > 0 && i < len && sig[i] != ')'; i++) {
+        while (i < len && sig[i] == '[') i++;
+        if (sig[i] == 'L') {
+            while (i < len && sig[i] != ';' && sig[i] != ')') i++;
+        }
+        index--;
+    }
+
+    if (index > 0 || (sig[i] != '[' && sig[i] != 'L')) return false;
+
+    size_t j = 0;
+    for (bool arrayFlag = false, classFlag = false; i < len; i++) {
+        char c = sig[i];
+        if (c == '[') {
+             if (classFlag) return false;
+             arrayFlag = true;
+             name[j++] = c;
+        } else if (c == 'L') {
+             if (classFlag) return false;
+             classFlag = true;
+             if (arrayFlag) {
+                 name[j++] = c;
+             }
+        } else if (c == ';') {
+             if (!classFlag) return false;
+             if (arrayFlag) {
+                 name[j++] = c;
+             }
+             break;
+        } else {
+             name[j++] = c;
+             if (arrayFlag && !classFlag) break;
+        }
+    }
+    name[j] = '\0';
+
+    return true;
+}
+
+jboolean
+SpecialAsyncCommandHandler::IsArgValid(JNIEnv *jni, jint index,
+                                       jdwpTaggedValue value, char* sig)
+                                       throw(AgentException)
+{
+    JDWP_TRACE_ENTRY("IsArgValid: index=" << index 
+        << ", value.tag=" << value.tag << ", arg tag=" << getTag(index, sig));
+    switch (value.tag) {
+        case JDWP_TAG_BOOLEAN:
+        case JDWP_TAG_BYTE:
+        case JDWP_TAG_CHAR:
+        case JDWP_TAG_SHORT:
+        case JDWP_TAG_INT:
+        case JDWP_TAG_LONG:
+        case JDWP_TAG_FLOAT:
+        case JDWP_TAG_DOUBLE:
+            if (value.tag != getTag(index, sig)) {
+                return JNI_FALSE;
+            } else {
+                return JNI_TRUE;
+            }
+        case JDWP_TAG_ARRAY:
+            if ('[' != getTag(index, sig)) {
+                return JNI_FALSE;
+            }
+            break;
+        case JDWP_TAG_OBJECT:
+        case JDWP_TAG_STRING:
+        case JDWP_TAG_THREAD:
+        case JDWP_TAG_THREAD_GROUP:
+        case JDWP_TAG_CLASS_LOADER:
+        case JDWP_TAG_CLASS_OBJECT:
+            if ('L' != getTag(index, sig)) {
+                return JNI_FALSE;
+            }
+            break;
+        default: 
+            return JNI_FALSE;
+    }
+    char* name = reinterpret_cast<char*>(GetMemoryManager().Allocate(strlen(sig) JDWP_FILE_LINE));
+    AgentAutoFree afv(name JDWP_FILE_LINE);
+    if (!getClassNameArg(index, sig, name)) {
+        return JNI_FALSE;
+    }
+    JDWP_TRACE_CMD("IsArgValid: name =" << JDWP_CHECK_NULL(name));
+    jclass cls = jni->FindClass(name);
+    if (jni->ExceptionCheck() == JNI_TRUE) {
+        jni->ExceptionClear();
+        return JNI_FALSE;
+    }
+    JDWP_TRACE_CMD("IsArgValid: class=" << cls);
+    return jni->IsInstanceOf(value.value.l, cls);
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,353 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin, Viacheslav G. Rybalov
+ * @version $Revision: 1.16.2.1 $
+ */
+
+/**
+ * @file
+ * CommandHandler.h
+ *
+ */
+
+#ifndef _COMMAD_HANDLER_H_
+#define _COMMAD_HANDLER_H_
+
+#include "jni.h"
+#include "jvmti.h"
+
+#include "AgentBase.h"
+#include "AgentException.h"
+#include "AgentMonitor.h"
+
+namespace jdwp {
+
+    class CommandParser;
+
+    /**
+     * A command handler is an object responsible for executing a
+     * JDWP command and composing a reply.
+     * The class <code>CommandHandler</code> is abstract and defines an
+     * interface for every command handlers.
+     * Two implementations of the given interface exist:
+     * <ul>
+     *   <li>The <code>SyncCommandHandler</code> class handles commands, which
+     *       are executed synchronously.
+     *   <li>The <code>AsyncCommandHandler</code> class handles commands, which
+     *       are executed asynchronously.
+     * </ul>
+     * All command handlers must be inherited from one of the mentioned 
+     * implementations.
+     *
+     * @see SyncCommandHandler
+     * @see AsyncCommandHandler
+     */
+    class CommandHandler : public AgentBase
+    {
+    public:
+        /**
+         * Constructs a new <code>PacketDispatcher</code> object.
+         */
+        CommandHandler() {m_cmdParser = 0;}
+
+        /**
+         * Destroys the given <code>PacketDispatcher</code> object.
+         */
+        virtual ~CommandHandler() {}
+
+        /**
+         * Starts an execution of the JDWP command passed with the
+         * <code>cmd</code> parameter.
+         * All command handlers inherited from <code>CommandHandler</code> must
+         * implement the given method.
+         *
+         * @param jni - the JNI interface pointer
+         * @param cmd - points to the <code>CommandParser</code> object
+         *
+         * @exception The implementations of the given interface may throw
+         *            <code>AgentException</code>.
+         */
+        virtual void Run(JNIEnv *jni, CommandParser *cmd) throw (AgentException) = 0;
+
+        /**
+         * Retuns the internal <code>CommandParser</code> instance.
+         *
+         * @return The internal <code>CommandParser</code> instance.
+         */
+        CommandParser* GetCommandParser() {return m_cmdParser;}
+
+        /**
+         * Identifies if the command handler performs the execution synchronously.
+         *
+         * @return Returns <code>TRUE</code> if JDWP-commands are executed
+         *         synchronously, otherwise <code>FALSE</code>.
+         */
+        virtual bool IsSynchronous() = 0;
+
+    protected:
+        CommandParser *m_cmdParser;
+
+        /**
+         * Defines the interface for all derived classes. The method 
+         * is intended to execute the JDWP command.
+         *
+         * @param jni - the JNI interface pointer
+         *
+         * @exception  If the packet data integrity gets broken,
+         * InternalErrorException is thrown.
+         *
+         * @exception The implementations of the given interface
+         * may throw AgentException.         
+         */
+        virtual void Execute(JNIEnv* jni) throw (AgentException) = 0;
+
+        /**
+         * Makes up reply with error based on the <code>AgentException<code> 
+         * object.
+         */
+        virtual void ComposeError(const AgentException &e);
+
+    };//class CommandHandler
+
+
+    /**
+     * Base class for synchronous command handlers.
+     */
+    class SyncCommandHandler : public CommandHandler
+    {
+    public:
+        /**
+         * Starts an execution of the JDWP-command passed with the
+         * <code>cmd</code> parameter.
+         *
+         * @param jni - the JNI interface pointer
+         * @param cmd - points to the object of <code>CommandParser</code>
+         *
+         * @exception If the reply to the given command can not be sent,
+         * TransportException is thrown.
+         */
+        virtual void Run(JNIEnv *jni, CommandParser *cmd) throw (AgentException);
+
+        /**
+         * Identifies if the command handler does execution synchronously.
+         *
+         * @return Always returns <code>TRUE</code>.
+         */
+        virtual bool IsSynchronous() {return true;}
+
+    };//class SyncCommandHandler
+
+
+    /**
+     * Base class for asynchronous command handlers.
+     */
+    class AsyncCommandHandler : public CommandHandler
+    {
+    public:
+        ~AsyncCommandHandler();
+
+        /**
+         * Starts an execution of the JDWP-command passed with the
+         * <code>cmd</code> parameter.
+         * Before the execution the given method copies the
+         * <code>cmd</code> parameter into the private object and starts the
+         * execution of the JDWP command in a separate thread.
+         *
+         * @param jni - the JNI interface pointer
+         * @param cmd - points to the object of <code>CommandParser</code>
+         *
+         * @exception If the system runs out of memory,
+         *            <code>OutOfMemoryException</code> is thrown.
+         * @exception <code>InternalErrorException</code> is thrown in any 
+         * other cases.
+         */
+        virtual void Run(JNIEnv *jni, CommandParser *cmd) throw (AgentException);
+
+        /**
+         * Identifies if the command handler does execution synchronously.
+         *
+         * @return Always returns <code>FALSE</code>.
+         */
+        virtual bool IsSynchronous() {return false;}
+
+        /**
+         * Gets a thread name for asynchronous execution of the given command
+         * handler.
+         *
+         * @return The thread name string.
+         */
+        virtual const char* GetThreadName();
+
+        /**
+         * Destroys the asynchronous command handler after execution.
+         */
+        virtual void Destroy() {delete this;}
+
+    protected:
+        /**
+         * The given method is passed as a parameter to the 
+         * <code>RunAgentThread()</code> method of the 
+         * <code>ThreadManager</code>class.
+         * The arg parameter is a pointer to an object of the corresponding
+         * <code>CommandHandler</code> class. At the end of the 
+         * <code>StartExecution</code> method the memory used by the given 
+         * object is released.
+         */
+        static void JNICALL StartExecution(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg);
+
+    };//class AsyncCommandHandler
+
+    /**
+     * Base class for special asynchronous command handlers for the deferred 
+     * method invocation.
+     */
+    class SpecialAsyncCommandHandler : public AsyncCommandHandler
+    {
+    public:
+        /**
+         * Creates a new instance.
+         */
+        SpecialAsyncCommandHandler();
+
+        /**
+         * Destroys the given instance.
+         */
+        ~SpecialAsyncCommandHandler();
+
+        /**
+         * Does not delete the given asynchronous command after execution.
+         * <code>ThreadManager</code> or <code>EventHandler</code> deletes it.
+         */
+        virtual void Destroy() {}
+
+        /**
+         * Returns method invocation options.
+         */
+        jint GetOptions() {
+            return m_invokeOptions;
+        }
+
+        /**
+         * Returns the thread for method invocation.
+         */
+        jthread GetThread() {
+            return m_thread;
+        }
+
+        /**
+         * Checks the flag if method invocation is completed.
+         */
+        bool IsInvoked() {
+            return m_isInvoked;
+        }
+
+        /**
+         * Sets the flag that method invocation is completed.
+         */
+        void SetInvoked(bool invoked) {
+            m_isInvoked = invoked;
+        }
+
+        /**
+         * Checks the flag if the thread is released after method invocation.
+         */
+        bool IsReleased() {
+            return m_isReleased;
+        }
+
+        /**
+         * Sets the flag that the thread is released after method invocation.
+         */
+        void SetReleased(bool released) {
+            m_isReleased = released;
+        }
+
+        /**
+         * Executes deferred method invocation.
+         */
+        void ExecuteDeferredInvoke(JNIEnv *jni);
+
+    protected:
+        
+        /**
+         * Initiates deferred invocation and waits for its completion.
+         */
+        void WaitDeferredInvocation(JNIEnv *jni);
+
+        /**
+         * The function to execute in deferred method invocation.
+         */
+        virtual void ExecuteDeferredFunc(JNIEnv *jni) = 0;
+
+        /**
+         * Calculates number of arguments for the given method signature.
+         */
+        jint getArgsNumber(char* methodSig);
+
+        /**
+         * Checks if provided method arguments are valid for the given method
+         * signature.
+         */
+        jboolean IsArgValid(JNIEnv *jni, jint index, jdwpTaggedValue value, char* methodSig) throw(AgentException);
+
+        /**
+         * The error occurred in method invocation.
+         */
+        jdwpError m_returnError;
+
+        /**
+         * Options for method invocation.
+         */
+        jint m_invokeOptions;
+        
+        /**
+         * The thread for method invocation.
+         */
+        jthread m_thread;
+        
+    private:
+
+        /**
+         * Returns a tag for a return value for the given method signature.
+         */
+        jdwpTag getTag(jint index, char* methodSig);
+        
+        /**
+         * Extracts the argument name for the given method signature.
+         */
+        bool getClassNameArg(jint index, char* sig, char* name);
+
+        /**
+         * The flag for synchronization of method invocation.
+         */
+        volatile bool m_isInvoked;
+        
+        /**
+         * The flag for synchronization of thread suspension after method 
+         * invocation.
+         */
+        volatile bool m_isReleased;
+
+    };//class SpecialAsyncCommandHandler
+
+}//namespace jdwp
+
+
+#endif //_COMMAD_HANDLER_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/CommandHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,442 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.24 $
+ */
+// EventDispatcher.cpp
+
+#include "EventDispatcher.h"
+#include "ThreadManager.h"
+#include "OptionParser.h"
+#include "Log.h"
+
+using namespace jdwp;
+
+EventDispatcher::EventDispatcher(size_t limit) throw() {
+    JDWP_ASSERT(limit > 0);
+    m_idCount = 0;
+    m_queueMonitor = 0;
+    m_waitMonitor = 0;
+    m_invokeMonitor = 0;
+    m_completeMonitor = 0;
+    m_stopFlag = true;
+    m_holdFlag = false;
+    m_resetFlag = false;
+    m_queueLimit = limit;
+}
+
+void EventDispatcher::Run(JNIEnv* jni) {
+    JDWP_TRACE_ENTRY("Run(" << jni << ')');
+
+    MonitorAutoLock malCM(m_completeMonitor JDWP_FILE_LINE);
+
+    while (!m_stopFlag) {
+        EventComposer *ec;
+
+        // get next event from queue
+        {
+            MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+            while (m_holdFlag || m_eventQueue.empty()) {
+                m_queueMonitor->Wait();
+                if (m_stopFlag) {
+                    return;
+                }
+            }
+            ec = m_eventQueue.front();
+            m_eventQueue.pop();
+            m_queueMonitor->NotifyAll();
+        }
+
+        // send event and suspend thread according to suspend policy
+        SuspendOnEvent(jni, ec);
+    }
+}
+
+void JNICALL
+EventDispatcher::StartFunction(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
+    JDWP_TRACE_ENTRY("StartFunction(" << jvmti << ',' << jni << ',' << arg << ')');
+
+    (reinterpret_cast<EventDispatcher*>(arg))->Run(jni);
+}
+
+void EventDispatcher::Init(JNIEnv *jni) throw(AgentException) {
+    JDWP_TRACE_ENTRY("Init(" << jni << ')');
+
+    m_queueMonitor = new AgentMonitor("_jdwp_EventDispatcher_queueMonitor");
+    m_waitMonitor = new AgentMonitor("_jdwp_EventDispatcher_waitMonitor");
+    m_invokeMonitor = new AgentMonitor("_jdwp_EventDispatcher_invokeMonitor");
+    m_completeMonitor = new AgentMonitor("_jdwp_EventDispatcher_completeMonitor");
+    m_stopFlag = false;
+    m_holdFlag = true;
+}
+
+void EventDispatcher::Start(JNIEnv *jni) throw(AgentException) {
+    JDWP_TRACE_ENTRY("Start(" << jni << ')');
+
+    GetThreadManager().RunAgentThread(jni, StartFunction, this,
+        JVMTI_THREAD_MAX_PRIORITY, "_jdwp_EventDispatcher");
+}
+
+void EventDispatcher::Reset(JNIEnv *jni) throw(AgentException) {
+    JDWP_TRACE_ENTRY("Reset(" << jni << ')');
+
+    m_resetFlag = true;
+
+    // dispose all remaining events in queue
+    if (m_queueMonitor != 0) {
+        MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+
+        while(!m_eventQueue.empty()) {
+            EventComposer *ec = m_eventQueue.front();
+            m_eventQueue.pop();
+            JDWP_TRACE_EVENT("Reset -- delete event set: packet=" << ec);
+            ec->Reset(jni);
+            delete ec;
+        }
+
+        m_holdFlag = true;
+    }
+    
+    // release all treads waiting for suspending by event
+    if (m_waitMonitor != 0) {
+        MonitorAutoLock lock(m_waitMonitor JDWP_FILE_LINE);
+        m_waitMonitor->NotifyAll();
+    }
+
+    // release all treads waiting for invoke method
+    if (m_invokeMonitor != 0) {
+        MonitorAutoLock lock(m_invokeMonitor JDWP_FILE_LINE);
+        m_invokeMonitor->NotifyAll();
+    }
+
+//    m_resetFlag = false;
+}
+
+void EventDispatcher::Stop(JNIEnv *jni) throw(AgentException) {
+    JDWP_TRACE_ENTRY("Stop(" << jni << ')');
+
+    // let thread loop to finish
+    {
+        MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+        m_stopFlag = true;
+        m_holdFlag = false;
+        m_queueMonitor->NotifyAll();
+    }
+
+    // wait for loop finished
+    {
+        MonitorAutoLock lock(m_completeMonitor JDWP_FILE_LINE);
+    } 
+
+}
+
+void EventDispatcher::Clean(JNIEnv *jni) throw(AgentException) {
+    JDWP_TRACE_ENTRY("Clean(" << jni << ')');
+    
+    // The following code is just a workaround for known problem
+    // in reset and clean-up procedure to release threads which
+    // may still wait on monitors.
+    // TODO: improve reset and clean-up procedure
+    {
+        // release all treads waiting for suspending by event
+        if (m_waitMonitor != 0) {
+            MonitorAutoLock lock(m_waitMonitor JDWP_FILE_LINE);
+            m_waitMonitor->NotifyAll();
+        }
+        
+        // release all treads waiting for invoke method
+        if (m_invokeMonitor != 0) {
+            MonitorAutoLock lock(m_invokeMonitor JDWP_FILE_LINE);
+            m_invokeMonitor->NotifyAll();
+        }
+    }
+
+    // delete monitors
+    
+    if (m_queueMonitor != 0) {
+        delete m_queueMonitor;
+        m_queueMonitor = 0;
+    }
+    if (m_waitMonitor != 0){
+        delete m_waitMonitor;
+        m_waitMonitor = 0;
+    }
+    if (m_invokeMonitor != 0){
+        delete m_invokeMonitor;
+        m_invokeMonitor = 0;
+    }
+    if (m_completeMonitor != 0){
+        delete m_completeMonitor;
+        m_completeMonitor = 0;
+    }
+
+    // clean counter for packet id
+
+    m_idCount = 0;
+}
+
+void EventDispatcher::HoldEvents() throw(AgentException) {
+    JDWP_TRACE_ENTRY("HoldEvents()");
+
+    MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+    m_holdFlag = true;
+}
+
+void EventDispatcher::ReleaseEvents() throw(AgentException) {
+    JDWP_TRACE_ENTRY("ReleaseEvents()");
+
+    MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+    m_holdFlag = false;
+    m_queueMonitor->NotifyAll();
+}
+
+void EventDispatcher::PostInvokeSuspend(JNIEnv *jni, SpecialAsyncCommandHandler* handler) 
+    throw(AgentException) 
+{
+    JDWP_TRACE_ENTRY("PostInvokeSuspend(" << jni << ',' << handler << ')');
+
+    MonitorAutoLock lock(m_invokeMonitor JDWP_FILE_LINE);
+    jthread thread = handler->GetThread();
+
+    char* threadName = 0;
+#ifndef NDEBUG
+        if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
+            jvmtiError err;
+            jvmtiThreadInfo threadInfo;
+            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+            threadName = threadInfo.name;
+        }
+#endif // NDEBUG
+    JvmtiAutoFree af(threadName);
+
+    // wait for thread to complete method invocation and ready for suspension
+    JDWP_TRACE_EVENT("PostInvokeSuspend -- wait for method invoked: thread=" << thread 
+            << ", name=" << JDWP_CHECK_NULL(threadName));
+    while (!handler->IsInvoked()) {
+        m_invokeMonitor->Wait();
+        if (m_resetFlag) {
+            return;
+        }
+    }
+
+    // suspend single thread or all threads accodring to invocation options
+    if ((handler->GetOptions() & JDWP_INVOKE_SINGLE_THREADED) == 0) {
+        JDWP_TRACE_EVENT("PostInvokeSuspend -- suspend all after method invoke: thread=" << thread 
+                << ", name=" << JDWP_CHECK_NULL(threadName));
+        GetThreadManager().SuspendAll(jni, handler->GetThread());
+    } else {
+        JDWP_TRACE_EVENT("PostInvokeSuspend -- suspend after method invoke: thread=" << thread 
+                << ", name=" << JDWP_CHECK_NULL(threadName));
+        GetThreadManager().Suspend(jni, handler->GetThread(), true);
+    }
+
+    // release thread after suspension
+    JDWP_TRACE_EVENT("SuspendOnEvent -- release after method invoke: thread=" << thread  
+                << ", name=" << JDWP_CHECK_NULL(threadName));
+    handler->SetReleased(true);
+    m_invokeMonitor->NotifyAll();
+}
+
+void EventDispatcher::SuspendOnEvent(JNIEnv* jni, EventComposer *ec)
+    throw(AgentException)
+{
+    JDWP_TRACE_EVENT("SuspendOnEvent -- send event set: id=" << ec->event.GetId()
+        << ", policy=" << ec->GetSuspendPolicy());
+    if (ec->GetSuspendPolicy() == JDWP_SUSPEND_NONE && !ec->IsAutoDeathEvent()) {
+        // thread is not waiting for suspension
+        ec->WriteEvent(jni);
+        JDWP_TRACE_EVENT("SuspendOnEvent -- delete event set: packet=" << ec);
+        ec->Reset(jni);
+        delete ec;
+    } else {
+        MonitorAutoLock lock(m_waitMonitor JDWP_FILE_LINE);
+        jthread thread = ec->GetThread();
+
+        char* threadName = 0;
+#ifndef NDEBUG
+        if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
+            jvmtiError err;
+            jvmtiThreadInfo threadInfo;
+            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+            threadName = threadInfo.name;
+        }
+#endif // NDEBUG
+        JvmtiAutoFree af(threadName);
+
+        // wait for thread to reach suspension point
+        JDWP_TRACE_EVENT("SuspendOnEvent -- wait for thread on event: thread=" << thread 
+                << ", name=" << JDWP_CHECK_NULL(threadName));
+        while (!ec->IsWaiting()) {
+            m_waitMonitor->Wait();
+            if (m_resetFlag) {
+                return;
+            }
+        }
+
+        // suspend corresponding threads if necessary
+        if (ec->GetSuspendPolicy() == JDWP_SUSPEND_ALL) {
+            JDWP_TRACE_EVENT("SuspendOnEvent -- suspend all threads on event: thread=" << thread 
+                    << ", name=" << JDWP_CHECK_NULL(threadName));
+            GetThreadManager().SuspendAll(jni, thread);
+        } else if (ec->GetSuspendPolicy() == JDWP_SUSPEND_EVENT_THREAD) {
+            JDWP_TRACE_EVENT("SuspendOnEvent -- suspend thread on event: thread=" << thread 
+                    << ", name=" << JDWP_CHECK_NULL(threadName));
+            JDWP_ASSERT(thread != 0);
+            GetThreadManager().Suspend(jni, thread, true);
+        }
+
+        // send event packet
+        ec->WriteEvent(jni);
+
+        // release thread on suspension point
+        JDWP_TRACE_EVENT("SuspendOnEvent -- release thread on event: thread=" << thread 
+                << ", name=" << JDWP_CHECK_NULL(threadName));
+        ec->SetReleased(true);
+        m_waitMonitor->NotifyAll();
+    }
+}
+
+void EventDispatcher::PostEventSet(JNIEnv *jni, EventComposer *ec, jdwpEventKind eventKind)
+    throw(AgentException)
+{
+    JDWP_TRACE_ENTRY("PostEventSet(" << jni << ',' << ec << ',' << eventKind << ')');
+
+    if (m_stopFlag) {
+        return;
+    }
+
+    jdwpSuspendPolicy suspendPolicy = ec->GetSuspendPolicy();
+    bool isAutoDeathEvent = ec->IsAutoDeathEvent();
+
+    // put event packet into queue
+    {
+        MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+        while (m_eventQueue.size() > m_queueLimit) {
+            m_queueMonitor->Wait();
+            if (m_resetFlag) {
+                JDWP_TRACE_EVENT("PostEventSet -- delete event set: packet=" << ec 
+                    << ", eventKind=" << eventKind);
+                ec->Reset(jni);
+                delete ec;
+                return;
+            }
+        }
+        m_eventQueue.push(ec);
+        m_queueMonitor->NotifyAll();
+    }
+
+    // if thread should be suspended
+    if (suspendPolicy != JDWP_SUSPEND_NONE || isAutoDeathEvent) {
+
+        jthread thread = ec->GetThread();
+
+        char* threadName = 0;
+#ifndef NDEBUG
+        if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
+            jvmtiError err;
+            jvmtiThreadInfo threadInfo;
+            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+            threadName = threadInfo.name;
+        }
+#endif // NDEBUG
+        JvmtiAutoFree af(threadName);
+        
+        // wait on suspension point
+        {
+            MonitorAutoLock lock(m_waitMonitor JDWP_FILE_LINE);
+            JDWP_TRACE_EVENT("PostEventSet -- wait for release on event: thread=" << thread
+                << ", name=" << JDWP_CHECK_NULL(threadName) << ", eventKind=" << eventKind);
+
+            // notify that thread is waiting on suspension point
+            ec->SetWaiting(true);
+            m_waitMonitor->NotifyAll();
+
+            // wait for thread to be released after suspension
+            while (!ec->IsReleased()) {
+                m_waitMonitor->Wait();
+                if (m_resetFlag) {
+                    return;
+                }
+            }
+
+            JDWP_TRACE_EVENT("PostEventSet -- released on event: thread=" << thread
+                << ", name=" << JDWP_CHECK_NULL(threadName) << ", eventKind=" << eventKind);
+        }
+        
+        // execute all registered InvokeMethod handlers sequentially
+        if (thread != 0 && suspendPolicy != JDWP_SUSPEND_NONE) {
+            ExecuteInvokeMethodHandlers(jni, thread);
+        }
+        
+        // delete event packet
+        JDWP_TRACE_EVENT("PostEventSet -- delete event set: packet=" << ec);
+        ec->Reset(jni);
+        delete ec;
+    }
+}
+
+void EventDispatcher::ExecuteInvokeMethodHandlers(JNIEnv *jni, jthread thread) throw(AgentException)
+{
+    // if reset process, don't invoke handlers
+    if (m_resetFlag) {
+        return;
+    }
+    
+    char* threadName = 0;
+#ifndef NDEBUG
+    jvmtiError err;
+    if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
+        jvmtiThreadInfo threadInfo;
+        JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+        threadName = threadInfo.name;
+    }
+#endif // NDEBUG
+
+    JvmtiAutoFree af(threadName);
+    
+    // if PopFrame process, don't invoke handlers
+    if (!GetThreadManager().IsPopFramesProcess(jni, thread)) {
+        SpecialAsyncCommandHandler* handler;
+        while ((handler =
+            GetThreadManager().FindInvokeHandler(jni, thread)) != 0)
+        {
+            JDWP_TRACE_EVENT("ExecuteInvokeMethodHandlers -- invoke method: thread=" << thread
+                << ", name=" << JDWP_CHECK_NULL(threadName) << ", handler=" << handler);
+            handler->ExecuteDeferredInvoke(jni);
+
+            MonitorAutoLock invokeMonitorLock(m_invokeMonitor JDWP_FILE_LINE);
+
+            // notify that thread is waiting on suspension point after method invocation
+            handler->SetInvoked(true);
+            m_invokeMonitor->NotifyAll();
+
+            // wait on suspension point after method invocation
+            JDWP_TRACE_EVENT("ExecuteInvokeMethodHandlers -- wait for released on event: thread=" << thread
+                << ", name=" << JDWP_CHECK_NULL(threadName) << ", handler=" << handler);
+            while (!handler->IsReleased()) {
+                m_invokeMonitor->Wait();
+                if (m_resetFlag) {
+                    return;
+                }
+            }
+            JDWP_TRACE_EVENT("ExecuteInvokeMethodHandlers -- released on event: thread=" << thread 
+                << ", name=" << JDWP_CHECK_NULL(threadName) << ", handler=" << handler);
+        }
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.11.2.1 $
+ */
+
+/**
+ * @file
+ * EventDispatcher.h
+ *
+ * Produces JDWP event packets and writes them to the transport.
+ * Operates in a separate agent thread.
+ */
+
+#ifndef _EVENT_DISPATCHER_H_
+#define _EVENT_DISPATCHER_H_
+
+#include <queue>
+
+#include "jni.h"
+#include "jvmti.h"
+#include "jdwp.h"
+
+#include "AgentBase.h"
+#include "AgentMonitor.h"
+#include "AgentAllocator.h"
+#include "PacketParser.h"
+#include "CommandHandler.h"
+
+
+namespace jdwp {
+
+    /**
+     * The given class provides a separate thread that dispatches all event packets, 
+     * suspends threads on events and performs deferred method invocation.
+     */
+    class EventDispatcher : public AgentBase {
+
+    public:
+
+        /**
+         * A constructor.
+         * Creates a new instance.
+         * 
+         * @param limit - maximum even queue length
+         */
+        EventDispatcher(size_t limit = 1024) throw();
+
+        /**
+         * A destructor.
+         * Destroys the given instance.
+         */
+        ~EventDispatcher() throw() {}
+
+        /**
+         * Initializes this events before starting the thread.
+         * 
+         * @param jni - the JNI interface pointer
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void Init(JNIEnv *jni) throw(AgentException);
+
+        /**
+         * Starts the given thread.
+         *
+         * @param jni - the JNI interface pointer
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void Start(JNIEnv *jni) throw(AgentException);
+
+        /**
+         * Resets all data.
+         *
+         * @param jni - the JNI interface pointer
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void Reset(JNIEnv *jni) throw(AgentException);
+
+        /**
+         * Stops the given thread.
+         *
+         * @param jni - the JNI interface pointer
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void Stop(JNIEnv *jni) throw(AgentException);
+
+        /**
+         * Cleans all data after thread completion.
+         *
+         * @param jni - the JNI interface pointer
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void Clean(JNIEnv *jni) throw(AgentException);
+
+        /**
+         * Turns on the flag to hold all events.
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void HoldEvents() throw(AgentException);
+
+        /**
+         * Turns off the flag to hold all events.
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void ReleaseEvents() throw(AgentException);
+
+        /**
+         * Generates new ID for the event packet.
+         */
+        jint NewId() throw() { return m_idCount++; }
+
+        /**
+         * Sends the event packet and suspends thread(s) according to suspend 
+         * policy.
+         *
+         * @param jni       - the JNI interface pointer
+         * @param ec        - the pointer to EventComposer
+         * @param eventKind - the JDWP event kind
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void PostEventSet(JNIEnv *jni, EventComposer *ec, jdwpEventKind eventKind)
+            throw(AgentException);
+
+        /**
+         * Suspends thread(s) after method invocation according to invocation 
+         * options.
+         *
+         * @param jni     - the JNI interface pointer
+         * @param handler - the pointer to SpecialAsyncCommandHandler
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void PostInvokeSuspend(JNIEnv *jni, SpecialAsyncCommandHandler* handler)
+            throw(AgentException);
+
+        /**
+         * Executes all handlers of methods that should be invoked on the 
+         * specified thread.
+         *
+         * @param jni    - the JNI interface pointer
+         * @param thread - the thread in which methods should be invoked
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void ExecuteInvokeMethodHandlers(JNIEnv *jni, jthread thread) 
+            throw(AgentException);
+
+    protected:
+
+        /**
+         * Starts the given thread.
+         *
+         * @param jvmti - the JVMTI interface pointer
+         * @param jni   - the JNI interface pointer
+         * @param arg   - the function argument
+         */
+        static void JNICALL
+            StartFunction(jvmtiEnv* jvmti, JNIEnv* jni, void* arg);
+
+        /**
+         * Performs the thread algorithm.
+         *
+         * @param jni - the JNI interface pointer
+         */
+        void Run(JNIEnv *jni);
+
+        /**
+         * Sends the event set and suspends thread(s) according to suspend 
+         * policy.
+         *
+         * @param jni - the JNI interface pointer
+         * @param ec  - the pointer to EventComposer
+         *
+         * @exception If any error occurs, <code>AgentException</code> is thrown.
+         */
+        void SuspendOnEvent(JNIEnv* jni, EventComposer *ec) throw(AgentException);
+
+        /**
+         * Event queue type.
+         */
+        typedef queue<EventComposer*,
+            deque<EventComposer*, AgentAllocator<EventComposer*> > > EventQueue;
+
+        /**
+         * Event queue with event packets to be sent.
+         */
+        EventQueue m_eventQueue;
+
+        /**
+         * Limit for events in <code>m_eventQueue</code>.
+         */
+        size_t m_queueLimit;
+
+        /**
+         * Counter for event-packet IDs.
+         */
+        jint m_idCount;
+
+        /**
+         * Monitor for <code>m_eventQueue</code>.
+         */
+        AgentMonitor* m_queueMonitor;
+
+        /**
+         * Monitor for synchronization of events sending.
+         */
+        AgentMonitor* m_waitMonitor;
+
+        /**
+         * Monitor for synchronization of methods invocation.
+         */
+        AgentMonitor* m_invokeMonitor;
+
+        /**
+         * Monitor for synchronization of the thread end.
+         */
+        AgentMonitor* m_completeMonitor;
+
+        /**
+         * Flag to hold all event packets in <code>m_eventQueue</code>.
+         */
+        bool volatile m_holdFlag;
+
+        /**
+         * Flag to stop the thread run.
+         */
+        bool volatile m_stopFlag;
+
+        /**
+         * Flag to reset all data.
+         */
+        bool volatile m_resetFlag;
+    };
+
+}
+
+#endif // _EVENT_DISPATCHER_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/EventDispatcher.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Log.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Log.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Log.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Log.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.9.2.1 $
+ */
+#ifndef _LOG_H_
+#define _LOG_H_
+
+#include <sstream>
+#include "LogManager.h"
+
+/**
+ * @file
+ * Log.h
+ *
+ * Macros in the given file provide functionality for tracing
+ * program execution in a debug mode except INFO and ERROR,
+ * which work in a release mode as well as in a debug one.
+ */
+
+/**
+ * Safe null-checking method for passing a string as a parameter.
+ */
+#define JDWP_CHECK_NULL(str) ( (str)==0 ? "(null)" : (str) )
+
+/**
+ * Traces messages using the corresponding method of a log manager.
+ */
+#define JDWP_MESSAGE(method, message) { \
+    std::ostringstream _oss; \
+    _oss << message; \
+    AgentBase::GetLogManager().method(_oss.str(), __FILE__, __LINE__); \
+}
+
+/**
+ * Traces INFO kind of the messages.
+ */
+#define JDWP_INFO(message) JDWP_MESSAGE(Info, message)
+
+/**
+ * Traces ERROR kind of the messages.
+ */
+#define JDWP_ERROR(message) JDWP_MESSAGE(Error, message)
+
+/**
+ * Traces messages of a specific kind. The macro is empty in a release mode.
+ */
+#define JDWP_TRACE(kind, message) JDWP_TRACE_EX(kind, __FILE__, __LINE__, message)
+
+#define JDWP_TRACE_CMD(message) JDWP_TRACE(LOG_KIND_CMD, message)
+#define JDWP_TRACE_EVENT(message) JDWP_TRACE(LOG_KIND_EVENT, message)
+#define JDWP_TRACE_PACKET(message) JDWP_TRACE(LOG_KIND_PACKET, message)
+#define JDWP_TRACE_THREAD(message) JDWP_TRACE(LOG_KIND_THREAD, message)
+#define JDWP_TRACE_DATA(message) JDWP_TRACE(LOG_KIND_DATA, message)
+#define JDWP_TRACE_MEMORY(message) JDWP_TRACE(LOG_KIND_MEMORY, message)
+#define JDWP_TRACE_MAP(message) JDWP_TRACE(LOG_KIND_MAP, message)
+#define JDWP_TRACE_JVMTI(message) JDWP_TRACE(LOG_KIND_JVMTI, message)
+#define JDWP_TRACE_FUNC(message) JDWP_TRACE(LOG_KIND_FUNC, message)
+#define JDWP_TRACE_MON(message) JDWP_TRACE(LOG_KIND_MON, message)
+#define JDWP_TRACE_UTIL(message) JDWP_TRACE(LOG_KIND_UTIL, message)
+#define JDWP_TRACE_PROG(message) JDWP_TRACE(LOG_KIND_PROG, message)
+
+/**
+ * Traces the JVMTI kind of the messages.
+ */
+#define JVMTI_TRACE(err, function_call) { \
+    JDWP_TRACE_JVMTI(">> " #function_call); \
+    err = function_call; \
+    JDWP_TRACE_JVMTI("<< " #function_call "=" << err); \
+}
+
+/**
+ * Prints the message and terminates the program execution.
+ */
+#define JDWP_DIE(message) { \
+    JDWP_ERROR(message); \
+    exit(1); \
+}
+
+#ifdef NDEBUG
+
+/**
+ * The given macros are empty in a release mode.
+ */
+#define JDWP_LOG(message)
+#define JDWP_TRACE_EX(kind, file, line, message)
+#define JDWP_TRACE_ENTRY(message)
+#define JDWP_ASSERT(assert)
+#define JDWP_TRACE_ENABLED(kind) false
+
+#define JDWP_FILE_LINE
+#define JDWP_FILE_LINE_PAR
+#define JDWP_FILE_LINE_INI
+#define JDWP_FILE_LINE_MPAR
+#define JDWP_FILE_LINE_DECL
+
+#else // !NDEBUG
+
+/**
+ * Traces LOG kind of the messages.
+ */
+#define JDWP_LOG(message) JDWP_MESSAGE(Log, message)
+
+/**
+ * Traces messages of a specific kind.
+ */
+#define JDWP_TRACE_EX(kind, file, line, message){ \
+    std::ostringstream _oss; \
+    _oss << message; \
+    AgentBase::GetLogManager().Trace(_oss.str(), file, line, kind); \
+}
+
+/**
+ * Traces the function kind of the messages.
+ */
+#define JDWP_TRACE_ENTRY(message) \
+    std::ostringstream _ose; \
+    _ose << message; \
+    JdwpTraceEntry _tre(_ose, __FILE__, __LINE__, LOG_KIND_FUNC);
+
+/**
+ * Verifies the expression and terminates the program execution, if it
+ * is <code>FALSE</code>.
+ */
+#define JDWP_ASSERT(assert) { \
+    if (!(assert)) { \
+        JDWP_DIE("assert \"" #assert "\" failed"); \
+    } \
+}
+
+/**
+ * Checks whether a specific kind of messages is enabled for logging.
+ */
+#define JDWP_TRACE_ENABLED(kind) AgentBase::GetLogManager().TraceEnabled(__FILE__, __LINE__, kind)
+
+/**
+ * The following macros provide placement for file and line parameters in a debug mode1.
+ */
+#define JDWP_FILE_LINE , __FILE__, __LINE__
+#define JDWP_FILE_LINE_PAR , const char *file, int line
+#define JDWP_FILE_LINE_INI , m_file(file), m_line(line)
+#define JDWP_FILE_LINE_MPAR , m_file, m_line
+#define JDWP_FILE_LINE_DECL const char* m_file; int m_line;
+
+#endif // NDEBUG
+
+#endif // _LOG_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Log.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.15 $
+ */
+// LogManager.cpp
+
+#include <iostream>
+#include <fstream>
+#include <cstring>
+#include <string>
+
+#include "LogManager.h"
+#include "AgentMonitor.h"
+
+using namespace jdwp;
+using namespace std;
+
+static struct {
+    const char* disp;
+    const char* name;
+}
+s_logKinds[LOG_KIND_NUM] = {
+    { "  UNK", "UNK" },
+    { "  CMD", "CMD" },
+    { "EVENT", "EVENT" },
+    { " PACK", "PACK" },
+    { " THRD", "THRD" },
+    { " DATA", "DATA" },
+    { "  MEM", "MEM" },
+    { "  MAP", "MAP" },
+    { "JVMTI", "JVMTI" },
+    { " FUNC", "FUNC" },
+    { "  MON", "MON" },
+    { " UTIL", "UTIL" },
+    { " PROG", "PROG" },
+    { "  LOG", "LOG" },
+    { " INFO", "INFO" },
+    { "ERROR", "ERROR" }
+};
+
+STDLogManager::STDLogManager() throw() :
+    m_logStream(&clog),
+    m_fileFilter(0),
+    m_monitor(0)
+{
+    for (int i = 0; i < LOG_KIND_NUM; i++) {
+        m_logKinds[i] = TRACE_KIND_NONE;
+    }
+    m_logKinds[LOG_KIND_INFO] = TRACE_KIND_ALWAYS;
+    m_logKinds[LOG_KIND_ERROR] = TRACE_KIND_ALWAYS;
+}
+
+void STDLogManager::Init(const char* log, const char* kindFilter, const char* srcFilter)
+    throw(AgentException)
+{
+    if (srcFilter != 0 && strcmp("all", srcFilter) == 0) {
+        srcFilter = 0; // null equvivalent to "all"
+    }
+
+    m_fileFilter = srcFilter;
+    bool hasFiles = m_fileFilter != 0;// && strstr(m_fileFilter, ".cpp") != 0;
+
+    if (kindFilter == 0 || strcmp("none", kindFilter) == 0) {
+        for (int i = 0; i < LOG_KIND_NUM; i++) {
+            m_logKinds[i] = TRACE_KIND_NONE;
+        }
+    }
+    else if (strcmp("all", kindFilter) == 0) {
+        for (int i = 0; i < LOG_KIND_NUM; i++) {
+            m_logKinds[i] = hasFiles ? TRACE_KIND_FILTER_FILE : TRACE_KIND_ALWAYS;
+        }
+    }
+    else {
+        for (int i = 0; i < LOG_KIND_NUM; i++) {
+            if (strstr(kindFilter, s_logKinds[i].name) != 0) {
+                m_logKinds[i] = hasFiles ? TRACE_KIND_FILTER_FILE : TRACE_KIND_ALWAYS;
+            }
+            else {
+                m_logKinds[i] = TRACE_KIND_NONE;
+            }
+        }
+    }
+
+    m_logKinds[LOG_KIND_INFO] = TRACE_KIND_ALWAYS;
+    m_logKinds[LOG_KIND_ERROR] = TRACE_KIND_ALWAYS;
+
+    if (log == 0) {
+        m_logStream = &clog;
+    } else {
+        m_logStream = new ofstream(log);
+        if (m_logStream == 0) {
+            fprintf(stderr, "Cannot open log file: %s\n", log);
+            m_logStream = &clog;
+        }
+    }
+
+    m_monitor = new AgentMonitor("_agent_Log");
+}
+
+void STDLogManager::Clean() throw()
+{
+    if (m_monitor != 0) {
+        m_monitor->Enter();
+    }
+
+    if (m_logStream != &clog) {
+        delete m_logStream;
+        m_logStream = &clog;
+    }
+
+    // prevent logging in destruction of log's monitor
+    AgentMonitor *monitor = m_monitor;
+    m_monitor = 0;
+    if (0 != monitor) {
+        monitor->Exit();
+        delete monitor; // <= STDLogManager instance will be called with m_monitor == 0
+    }
+}
+
+// extract basename from filename
+
+const char* STDLogManager::BaseName(const char* filepath) throw()
+{
+    size_t len;
+
+    if (filepath == 0)
+        return "";
+
+    len = strlen(filepath);
+    if (len == 0)
+        return filepath;
+
+    for (size_t i = len-1; i > 0; i--) {
+        if (filepath[i] == '/' || filepath[i] == '\\' ) {
+            return &filepath[i+1];
+        }
+    }
+
+    return filepath;
+}
+
+// STDLogManager intended to use cout, cerr and clog streams.
+
+void STDLogManager::Info(const std::string& message,
+        const char *file, int line) throw()
+{
+    Trace(message, file, line, LOG_KIND_INFO);
+}
+
+void STDLogManager::Error(const std::string& message,
+        const char *file, int line) throw()
+{
+    Trace(message, file, line, LOG_KIND_ERROR);
+}
+
+void STDLogManager::Log(const std::string& message,
+        const char *file, int line) throw()
+{
+    Trace(message, file, line, LOG_KIND_LOG);
+}
+
+void STDLogManager::Trace(const string& message,
+        const char *file, int line, int kind) throw()
+{
+    if (TraceEnabled(file, line, kind)){
+        if (m_monitor != 0) {
+            m_monitor->Enter();
+        }
+
+        file = BaseName(file);
+        std::ostream* logStream = m_logStream;
+        if (LOG_KIND_ERROR == kind) {
+            logStream = &cerr;
+        }
+        else if (LOG_KIND_INFO == kind) {
+            logStream = &cout;
+        }
+
+        *logStream
+                << s_logKinds[kind].disp << ": "
+                << "[" << file << ":" << line << "] "
+                << message << endl;
+
+        // duplicate ERROR and INFO message in the log and in the cerr/cout output
+        if (logStream != m_logStream && m_logStream != &clog) {
+            *m_logStream
+                << s_logKinds[kind].disp << ": "
+                << "[" << file << ":" << line << "] "
+                << message << endl;
+        }
+
+        if (m_monitor != 0) {
+            m_monitor->Exit();
+        }
+    }
+}
+
+bool STDLogManager::TraceEnabled(const char *file, int line, int kind) throw()
+{
+    if (TRACE_KIND_FILTER_FILE == m_logKinds[kind]) {
+        return strstr(m_fileFilter, BaseName(file)) != 0;
+    }
+    else {
+        return TRACE_KIND_ALWAYS == m_logKinds[kind];
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.12.2.1 $
+ */
+
+/**
+ * @file
+ * LogManager.h
+ *
+ */
+
+#ifndef _LOG_MANAGER_H_
+#define _LOG_MANAGER_H_
+
+#include <iostream>
+#include <string>
+
+#include "AgentException.h"
+
+namespace jdwp {
+
+    /**
+     * Log kinds enumeration.
+     */
+    enum {
+        LOG_KIND_UNKNOWN = 0,
+        LOG_KIND_CMD,
+        LOG_KIND_EVENT,
+        LOG_KIND_PACKET,
+        LOG_KIND_THREAD,
+        LOG_KIND_DATA,
+        LOG_KIND_MEMORY,
+        LOG_KIND_MAP,
+        LOG_KIND_JVMTI,
+        LOG_KIND_FUNC,
+        LOG_KIND_MON,
+        LOG_KIND_UTIL,
+        LOG_KIND_PROG,
+        LOG_KIND_LOG,
+        LOG_KIND_INFO,
+        LOG_KIND_ERROR,
+
+        LOG_KIND_NUM
+    };
+
+    /**
+     * Trace kinds enumeration.
+     */
+    enum {
+        TRACE_KIND_NONE = 0,
+        TRACE_KIND_FILTER_FILE,
+        TRACE_KIND_ALWAYS
+    };
+
+    class AgentMonitor;
+
+    /**
+     * Log manager interface.
+     */
+    class LogManager {
+
+    public:
+
+        /**
+         * Initializes the log manager.
+         */
+        virtual void Init(const char* log, const char* kindFilter, const char* srcFilter)
+            throw(AgentException) = 0;
+
+        /**
+         * Cleanups the log manager.
+         */
+        virtual void Clean() throw() = 0;
+
+        /**
+         * Prints the given message of the Info type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         */
+        virtual void Info(const std::string& message,
+            const char *file, int line) throw() = 0;
+
+        /**
+         * Prints the given message of the Error type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         */
+        virtual void Error(const std::string& message,
+            const char *file, int line) throw() = 0;
+
+        /**
+         * Prints the given message of the Log type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         */
+        virtual void Log(const std::string& message,
+            const char *file, int line) throw() = 0;
+
+        /**
+         * Prints the given message of the Trace type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         * @param kind    - the log kind
+         */
+        virtual void Trace(const std::string& message,
+            const char *file, int line, int kind) throw() = 0;
+
+        /**
+         * Checks whether the print to log is enabled for the Trace log type.
+         *
+         * @param file - the name of the source file (__FILE__ macro)
+         * @param line - the number of the code line (__LINE__ macro)
+         * @param kind - the log kind
+         *
+         * @return Boolean.
+         */
+        virtual bool TraceEnabled(const char *file, int line, int kind) throw() = 0;
+    };
+
+    /**
+     * JDWP Log manager class.
+     */
+    class STDLogManager : public LogManager {
+
+    public:
+
+        /**
+         * A constructor.
+         */
+        STDLogManager() throw();
+
+        /**
+         * Initializes the log manager.
+         */
+        void Init(const char* log, const char* kindFilter, const char* srcFilter)
+            throw(AgentException);
+
+        /**
+         * Cleanups the log manager.
+         */
+        void Clean() throw();
+
+        /**
+         * Prints the given message of the Info type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         */
+        void Info(const std::string& message,
+            const char *file, int line) throw();
+
+        /**
+         * Prints the given message of the Error type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         */
+        void Error(const std::string& message,
+            const char *file, int line) throw();
+
+        /**
+         * Prints the given message of the Log type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         */
+        void Log(const std::string& message,
+            const char *file, int line) throw();
+
+        /**
+         * Prints the given message of the Trace type.
+         *
+         * @param message - the log message
+         * @param file    - the name of the source file (__FILE__ macro)
+         * @param line    - the number of the code line (__LINE__ macro)
+         * @param kind    - the log kind
+         */
+        void Trace(const std::string& message,
+            const char *file, int line, int kind) throw();
+
+        /**
+         * Checks whether the print to log is enabled for the Trace log type.
+         *
+         * @param file - the name of the source file (__FILE__ macro)
+         * @param line - the number of the code line (__LINE__ macro)
+         * @param kind - log kind
+         *
+         * @return Boolean.
+         */
+        bool TraceEnabled(const char *file, int line, int kind) throw();
+
+        /**
+         * Gets a short file name from the full path.
+         *
+         * @param filepath - the path name
+         *
+         * @return Zero terminated string.
+         */
+        static const char* BaseName(const char* filepath) throw();
+
+    private:
+        const char*     m_fileFilter;
+        std::ostream*   m_logStream;
+        AgentMonitor*   m_monitor;
+        int             m_logKinds[LOG_KIND_NUM];
+    };
+}
+
+#endif // _LOG_MANAGER_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/LogManager.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.5 $
+ */
+// MemoryManager.cpp
+
+#include <cstdlib>
+#include <cstring>
+
+#include "AgentException.h"
+#include "MemoryManager.h"
+#include "AgentBase.h"
+//#include "Log.h"
+//#include "jvmti.h"
+
+using namespace jdwp;
+
+// STDMemoryManager intended to use std::malloc(), std::free() etc.
+
+void* STDMemoryManager::AllocateNoThrow(size_t size JDWP_FILE_LINE_PAR) throw() {
+    void *p = std::malloc(size);
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD malloc: " << static_cast<long long>(size) << " " << p);
+    return p;
+}
+
+void* STDMemoryManager::Allocate(size_t size JDWP_FILE_LINE_PAR) throw(AgentException) {
+    void *p = std::malloc(size);
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD malloc: " << static_cast<long long>(size) << " " << p);
+    if (p == 0) {
+        throw OutOfMemoryException();
+    }
+    return p;
+}
+
+void* STDMemoryManager::Reallocate(void* ptr, size_t oldSize, size_t newSize JDWP_FILE_LINE_PAR)
+        throw(AgentException) {
+    void *p = std::realloc(ptr, newSize);
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD realloc: " << ptr << " " << static_cast<long long>(oldSize)
+        << "/" << static_cast<long long>(newSize) << " " << p);
+    if (p == 0) {
+        throw OutOfMemoryException();
+    }
+    return p;
+}
+
+void STDMemoryManager::Free(void* ptr JDWP_FILE_LINE_PAR) throw() {
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD free: " << ptr);
+    std::free(ptr);
+}
+
+
+// VMMemoryManager intended to use JVMTI's Allocate() and Deallocate()
+
+void* VMMemoryManager::AllocateNoThrow(size_t size JDWP_FILE_LINE_PAR) throw() {
+    void *p;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Allocate(size,
+        reinterpret_cast<unsigned char**>(&p)));
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM malloc: " << static_cast<long long>(size) << ", " << p);
+    return ((err == JVMTI_ERROR_NONE) ? p : 0);
+}
+
+void* VMMemoryManager::Allocate(size_t size JDWP_FILE_LINE_PAR) throw(AgentException) {
+    void *p;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Allocate(size,
+        reinterpret_cast<unsigned char**>(&p)));
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM malloc: " << static_cast<long long>(size) << ", " << p);
+    if (err != JVMTI_ERROR_NONE) {
+        throw AgentException(err);
+    }
+
+    return p;
+}
+
+void* VMMemoryManager::Reallocate(void* ptr, size_t oldSize, size_t newSize JDWP_FILE_LINE_PAR)
+        throw(AgentException) {
+    void *p;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Allocate(newSize,
+        reinterpret_cast<unsigned char**>(&p)));
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM realloc: " << ptr << " " << static_cast<long long>(oldSize)
+        << "/" << static_cast<long long>(newSize) << " " << p);
+    if (err != JVMTI_ERROR_NONE) {
+        throw AgentException(err);
+    } else {
+        std::memcpy(p, ptr, (newSize < oldSize) ? newSize : oldSize);
+        JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Deallocate(
+            reinterpret_cast<unsigned char*>(ptr)));
+        JDWP_ASSERT(err==JVMTI_ERROR_NONE);
+    }
+
+    return p;
+}
+
+void VMMemoryManager::Free(void* ptr JDWP_FILE_LINE_PAR) throw() {
+    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM free: " << ptr);
+    jvmtiError err;
+    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Deallocate(
+        reinterpret_cast<unsigned char*>(ptr)));
+    JDWP_ASSERT(err==JVMTI_ERROR_NONE);
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Pavel N. Vyssotski
+ * @version $Revision: 1.6.2.1 $
+ */
+
+/**
+ * @file
+ * MemoryManager.h
+ *
+ */
+
+#ifndef _MEMORY_MANAGER_H_
+#define _MEMORY_MANAGER_H_
+
+#include "AgentException.h"
+#include "Log.h"
+
+namespace jdwp {
+
+    /**
+     * Agent memory manager interface.
+     */
+    class MemoryManager {
+
+    public:
+
+        /**
+         * Allocates the memory block with the given size without throwing
+         * the <code>OutOfMemoryException</code> exception.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         */
+        virtual void* AllocateNoThrow(size_t size
+            JDWP_FILE_LINE_PAR) throw() = 0;
+
+        /**
+         * Allocates the memory block with the given size.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         *
+         * @exception If memory cannot be allocated,
+         *            <code>OutOfMemoryException</code> is thrown.
+         */
+        virtual void* Allocate(size_t size
+            JDWP_FILE_LINE_PAR) throw(AgentException) = 0;
+
+        /**
+         * Reallocates the memory block with the given size over the previously
+         * allocated block.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         *
+         * @exception If memory cannot be allocated,
+         *            <code>OutOfMemoryException</code> is thrown.
+         */
+        virtual void* Reallocate(void* ptr, size_t oldSize, size_t newSize
+            JDWP_FILE_LINE_PAR) throw(AgentException) = 0;
+
+        /**
+         * Frees the memory block with the given size.
+         *
+         * @param ptr - the pointer to the allocated memory block
+         */
+        virtual void Free(void* ptr
+            JDWP_FILE_LINE_PAR) throw() = 0;
+    };
+
+    /**
+     * The standard memory manager implementation that uses 
+     * allocation/deallocation functions from std namespace.
+     */
+    class STDMemoryManager : public MemoryManager {
+
+    public:
+
+        /**
+         * Allocates the memory block with the given size without throwing
+         * <code>OutOfMemoryException</code> exception.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         */
+        void* AllocateNoThrow(size_t size
+            JDWP_FILE_LINE_PAR) throw();
+
+        /**
+         * Allocates the memory block with the given size.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         *
+         * @exception If memory cannot be allocated,
+         *            <code>OutOfMemoryException</code> is thrown.
+         */
+        void* Allocate(size_t size
+            JDWP_FILE_LINE_PAR) throw(AgentException);
+
+        /**
+         * Reallocates the memory block with the given size over the previously
+         * allocated block.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         *
+         * @exception If memory cannot be allocated,
+         *            <code>OutOfMemoryException</code> is thrown.
+         */
+        void* Reallocate(void* ptr, size_t oldSize, size_t newSize
+            JDWP_FILE_LINE_PAR) throw(AgentException);
+
+        /**
+         * Frees the memory block with the given size.
+         *
+         * @param ptr - the pointer to the allocated memory block
+         */
+        void Free(void* ptr
+            JDWP_FILE_LINE_PAR) throw();
+    };
+
+
+    /**
+     * The memory manager implementation that uses 
+     * allocation/deallocation methods from the JVMTI environment.
+     */
+    class VMMemoryManager : public MemoryManager {
+
+    public:
+
+        /**
+         * Allocates the memory block with the given size without throwing
+         * <code>OutOfMemoryException</code> exception.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         */
+        void* AllocateNoThrow(size_t size
+            JDWP_FILE_LINE_PAR) throw();
+
+        /**
+         * Allocates the memory block with the given size.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         *
+         * @exception If memory cannot be allocated,
+         *            <code>OutOfMemoryException</code> is thrown.
+         */
+        void* Allocate(size_t size
+            JDWP_FILE_LINE_PAR) throw(AgentException);
+
+        /**
+         * Reallocates the memory block with the given size over the previously
+         * allocated block.
+         *
+         * @param size - the allocation size
+         *
+         * @return Pointer to the allocated memory block.
+         *
+         * @exception If memory cannot be allocated,
+         *            <code>OutOfMemoryException</code> is thrown.
+         */
+        void* Reallocate(void* ptr, size_t oldSize, size_t newSize
+            JDWP_FILE_LINE_PAR) throw(AgentException);
+
+        /**
+         * Frees the memory block with the given size.
+         *
+         * @param ptr - the pointer to the allocated memory block
+         */
+        void Free(void* ptr
+            JDWP_FILE_LINE_PAR) throw();
+    };
+}
+
+#endif // _MEMORY_MANAGER_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/MemoryManager.h
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message