harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r480141 [7/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/commands/VirtualMachine.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,733 @@
+/*
+ * 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.23.2.2 $
+ */
+#include "jvmti.h"
+#include "jdwp.h"
+
+#include "VirtualMachine.h"
+#include "PacketParser.h"
+#include "PacketDispatcher.h"
+#include "ThreadManager.h"
+#include "ClassManager.h"
+#include "ObjectManager.h"
+#include "EventDispatcher.h"
+#include "TransportManager.h"
+
+using namespace jdwp;
+using namespace VirtualMachine;
+
+//-----------------------------------------------------------------------------
+//VersionHandler---------------------------------------------------------------
+
+void
+VirtualMachine::VersionHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    ClassManager &clsMgr = AgentBase::GetClassManager();
+
+    char* javaVmVersion = clsMgr.GetProperty(jni, "java.vm.version");
+    AgentAutoFree dobj_javaVmVersion(javaVmVersion JDWP_FILE_LINE);
+
+    char *javaVersion = clsMgr.GetProperty(jni, "java.version");
+    AgentAutoFree dobj_javaVersion(javaVersion JDWP_FILE_LINE);
+
+    char *javaVmName = clsMgr.GetProperty(jni, "java.vm.name");
+    AgentAutoFree dobj_javaVmName(javaVmName JDWP_FILE_LINE);
+
+    char *javaVmInfo = clsMgr.GetProperty(jni, "java.vm.info");
+    AgentAutoFree dobj_javaVmInfo(javaVmInfo JDWP_FILE_LINE);
+
+    const char pattern[] = "JVM version %s (%s, %s, %s)";
+    const char unknown[] = "?";
+    size_t descriptionSize = sizeof(pattern) +
+        strlen((javaVersion == 0) ? unknown : javaVersion) +
+        strlen((javaVmName == 0) ? unknown : javaVmName) +
+        strlen((javaVmInfo == 0) ? unknown : javaVmInfo) +
+        strlen((javaVmVersion == 0) ? unknown : javaVmVersion);
+    char *description = reinterpret_cast<char*>
+        (AgentBase::GetMemoryManager().Allocate(descriptionSize JDWP_FILE_LINE));
+    AgentAutoFree dobj_description(description JDWP_FILE_LINE);
+    sprintf(description, pattern,
+        (javaVersion == 0) ? unknown : javaVersion,
+        (javaVmName == 0) ? unknown : javaVmName,
+        (javaVmInfo == 0) ? unknown : javaVmInfo,
+        (javaVmVersion == 0) ? unknown : javaVmVersion);
+
+    JDWP_TRACE_DATA("Version: send: "
+        << ", description=" << JDWP_CHECK_NULL(description)
+        << ", jdwpMajor=" << JDWP_VERSION_MAJOR
+        << ", jdwpMinor=" << JDWP_VERSION_MINOR
+        << ", vmVersion=" << JDWP_CHECK_NULL(javaVersion)
+        << ", vmVersion=" << JDWP_CHECK_NULL(javaVmName)
+
+    );
+
+    m_cmdParser->reply.WriteString(description);
+    m_cmdParser->reply.WriteInt(JDWP_VERSION_MAJOR);
+    m_cmdParser->reply.WriteInt(JDWP_VERSION_MINOR);
+    m_cmdParser->reply.WriteString(javaVersion);
+    m_cmdParser->reply.WriteString(javaVmName);
+}
+
+//-----------------------------------------------------------------------------
+//ClassesBySignatureHandler----------------------------------------------------
+
+void
+VirtualMachine::ClassesBySignatureHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    const char *signature = m_cmdParser->command.ReadString();
+    JDWP_TRACE_DATA("ClassesBySignature: received: "
+        << "signature=" << JDWP_CHECK_NULL(signature));
+
+    jint classCount = 0;
+    jclass* classes = 0;
+
+    jvmtiEnv* jvmti = AgentBase::GetJvmtiEnv();
+
+    jvmtiError err;
+    JVMTI_TRACE(err, jvmti->GetLoadedClasses(&classCount, &classes));
+    JvmtiAutoFree dobj(classes);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    int i;
+    int count = 0;
+    for (i = 0; i < classCount; i++)
+    {
+        if (IsSignatureMatch(classes[i], signature)) {
+            classes[count] = classes[i];
+            count++;
+        }
+    }
+    m_cmdParser->reply.WriteInt(count);
+    JDWP_TRACE_DATA("ClassesBySignature: classes=" << count);
+    
+    for (i = 0; i < count; i++)
+    {
+        jdwpTypeTag refTypeTag = GetClassManager().GetJdwpTypeTag(classes[i]);
+        m_cmdParser->reply.WriteByte(refTypeTag);
+
+        m_cmdParser->reply.WriteReferenceTypeID(jni, classes[i]);
+
+        jint status;
+        JVMTI_TRACE(err, jvmti->GetClassStatus(classes[i], &status));
+        if (err != JVMTI_ERROR_NONE)
+            throw AgentException(err);
+
+        if (status == JVMTI_CLASS_STATUS_ARRAY) {
+           status = 0;
+        } else {
+            if ( status == JVMTI_CLASS_STATUS_PRIMITIVE ) {
+                status = 0;
+            }
+        }
+        m_cmdParser->reply.WriteInt(status);
+#ifndef NDEBUG
+        if (JDWP_TRACE_ENABLED(LOG_KIND_DATA)) {    
+            jvmtiError err;
+            char* signature = 0;
+            JVMTI_TRACE(err, jvmti->GetClassSignature(classes[i], &signature, 0));
+            JvmtiAutoFree afcs(signature);
+            JDWP_TRACE_DATA("ClassesBySignature: class#=" << i
+                << ", refTypeID=" << classes[i]
+                << ", status=" << status
+                << ", signature=" << JDWP_CHECK_NULL(signature));
+        }
+#endif
+    }
+}
+
+bool
+VirtualMachine::ClassesBySignatureHandler::IsSignatureMatch(jclass klass,
+                                                            const char *signature)
+                                                            throw(AgentException)
+{
+    char* sign = 0;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, GetJvmtiEnv()->GetClassSignature(klass, &sign, 0));
+    JvmtiAutoFree dobj(sign);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    return strcmp(signature, sign) == 0;
+}
+
+//-----------------------------------------------------------------------------
+//AllClassesHandler------------------------------------------------------------
+
+void
+VirtualMachine::AllClassesHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    jint classCount = 0;
+    jclass* classes = 0;
+
+    jvmtiEnv* jvmti = AgentBase::GetJvmtiEnv();
+    jvmtiError err;
+    JVMTI_TRACE(err, jvmti->GetLoadedClasses(&classCount, &classes));
+
+    JvmtiAutoFree dobj(classes);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    JDWP_TRACE_DATA("AllClasses: classes=" << classCount);
+    m_cmdParser->reply.WriteInt(classCount);
+
+    // don't trace signatures of all classes
+    for (int i = 0; i < classCount; i++) {
+        Compose41Class(jni, jvmti, classes[i]);
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+void
+VirtualMachine::AllClassesHandler::Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti,
+        jclass klass) throw (AgentException)
+{
+    jdwpTypeTag refTypeTag = GetClassManager().GetJdwpTypeTag(klass);
+
+    m_cmdParser->reply.WriteByte(refTypeTag);
+    m_cmdParser->reply.WriteReferenceTypeID(jni, klass);
+
+    char* signature = 0;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, jvmti->GetClassSignature(klass, &signature, 0));
+
+    JvmtiAutoFree dobj(signature);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    m_cmdParser->reply.WriteString(signature);
+
+    jint status;
+    JVMTI_TRACE(err, jvmti->GetClassStatus(klass, &status));
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    // According to JVMTI spec ClassStatus flag for arrays and primitive classes must be zero
+    if (status == JVMTI_CLASS_STATUS_ARRAY) {
+        status = 0;
+    } else {
+        if (status == JVMTI_CLASS_STATUS_PRIMITIVE) {
+            JDWP_INFO("WARNING: GetLoadedClasses() returned primitive type with signature: " 
+                << JDWP_CHECK_NULL(signature));
+            status = 0;
+        }
+    }
+
+    m_cmdParser->reply.WriteInt(status);
+}
+
+//-----------------------------------------------------------------------------
+//AllThreadHandler-------------------------------------------------------------
+
+void
+VirtualMachine::AllThreadsHandler::Execute(JNIEnv *jni)
+    throw(AgentException)
+{
+    jint totalThreadsCount, threadsCount;
+    jthread* threads = 0;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, GetJvmtiEnv()->GetAllThreads(&totalThreadsCount, &threads));
+
+    JvmtiAutoFree dobj(threads);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    threadsCount = 0;
+    ThreadManager& thrdMgr = GetThreadManager();
+
+    JDWP_TRACE_DATA("AllThreads: threads=" << totalThreadsCount);
+
+    int i;
+    for (i = 0; i < totalThreadsCount; i++)
+    {
+
+#ifndef NDEBUG
+        if (JDWP_TRACE_ENABLED(LOG_KIND_DATA)) {
+            jvmtiThreadInfo info;
+            info.name = 0;
+            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(threads[i], &info));
+            JvmtiAutoFree jafInfoName(info.name);
+            JDWP_TRACE_DATA("AllThreads: thread#=" << i 
+                << ", name=" << JDWP_CHECK_NULL(info.name)
+                << ", isAgent=" << (thrdMgr.IsAgentThread(jni, threads[i])));
+        }
+#endif
+
+        // don't report internal agent threads
+        if ( !thrdMgr.IsAgentThread(jni, threads[i]) ) {
+            threads[threadsCount] = threads[i];
+            threadsCount++;
+        }
+    }
+
+    m_cmdParser->reply.WriteInt(threadsCount);
+    for (i = 0; i < threadsCount; i++)
+    {
+        m_cmdParser->reply.WriteThreadID(jni, threads[i]);
+    }
+}
+
+//-----------------------------------------------------------------------------
+//TopLevelThreadGroupsHandler--------------------------------------------------
+
+void
+VirtualMachine::TopLevelThreadGroupsHandler::Execute(JNIEnv *jni)
+    throw(AgentException)
+{
+    jint groupCount;
+    jthreadGroup* groups = 0;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, GetJvmtiEnv()->GetTopThreadGroups(&groupCount, &groups));
+
+    JvmtiAutoFree dobj(groups);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    JDWP_TRACE_DATA("TopLevelThreadGroup: send: groupCount=" << groupCount);
+    m_cmdParser->reply.WriteInt(groupCount);
+    for (jint i = 0; i < groupCount; i++) {
+
+#ifndef NDEBUG    
+        if (JDWP_TRACE_ENABLED(LOG_KIND_DATA)) {
+            for (i = 0; i < groupCount; i++) {
+                jvmtiThreadGroupInfo info;
+                info.name = 0;
+                JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadGroupInfo(groups[i], &info));
+                JvmtiAutoFree jafInfoName(info.name);
+        
+                JDWP_TRACE_DATA("TopLevelThreadGroup: send: group#" << i 
+                << ", groupID=" << groups[i]
+                << ", name=" << JDWP_CHECK_NULL(info.name));
+            }
+        }
+#endif
+
+        m_cmdParser->reply.WriteThreadGroupID(jni, groups[i]);
+    }
+}
+
+//-----------------------------------------------------------------------------
+//DisposeHandler---------------------------------------------------------------
+
+void
+VirtualMachine::DisposeHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    JDWP_TRACE_DATA("Dispose: write reply");
+    m_cmdParser->WriteReply(jni);
+    JDWP_TRACE_DATA("Dispose: reset agent");
+    GetPacketDispatcher().Reset(jni);
+}
+
+//-----------------------------------------------------------------------------
+//IDSizesHandler---------------------------------------------------------------
+
+void
+VirtualMachine::IDSizesHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    m_cmdParser->reply.WriteInt(FIELD_ID_SIZE);
+    m_cmdParser->reply.WriteInt(METHOD_ID_SIZE);
+    m_cmdParser->reply.WriteInt(OBJECT_ID_SIZE);
+    m_cmdParser->reply.WriteInt(REFERENCE_TYPE_ID_SIZE);
+    m_cmdParser->reply.WriteInt(FRAME_ID_SIZE);
+}
+
+//-----------------------------------------------------------------------------
+//SuspendHandler---------------------------------------------------------------
+
+void
+VirtualMachine::SuspendHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    JDWP_TRACE_DATA("Suspend: suspendAll");
+    GetThreadManager().SuspendAll(jni);
+}
+
+//-----------------------------------------------------------------------------
+//ResumedHandler---------------------------------------------------------------
+
+void
+VirtualMachine::ResumeHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    JDWP_TRACE_DATA("Resume: resumeAll");
+    GetThreadManager().ResumeAll(jni);
+}
+
+//-----------------------------------------------------------------------------
+//ExitHandler------------------------------------------------------------------
+
+void
+VirtualMachine::ExitHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    jint exitCode = m_cmdParser->command.ReadInt();
+    JDWP_TRACE_DATA("Exit: received: exitCode=" << exitCode);
+
+    JDWP_TRACE_DATA("Exit: write reply");
+    m_cmdParser->WriteReply(jni);
+
+    JDWP_TRACE_DATA("Exit: reset agent");
+    GetTransportManager().Reset();
+    
+    JDWP_TRACE_DATA("Exit: terminate process");
+    exit(static_cast<int>(exitCode));
+
+/*
+    // another variant is to call System.exit()
+    ClassManager &clsMgr = AgentBase::GetClassManager();
+    jclass klass = clsMgr.GetSystemClass();
+    jmethodID methodID = jni->GetStaticMethodID(klass, "exit", "(I)V");
+    clsMgr.CheckOnException(jni);
+
+    jni->CallStaticVoidMethod(klass, methodID, exitCode);
+    clsMgr.CheckOnException(jni);
+*/
+}
+
+//-----------------------------------------------------------------------------
+//CreateStringHandler----------------------------------------------------------
+
+void
+VirtualMachine::CreateStringHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    const char *utf = m_cmdParser->command.ReadString();
+    JDWP_TRACE_DATA("CreateString: received: string=" << JDWP_CHECK_NULL(utf));
+    jstring str = jni->NewStringUTF(utf);
+
+    JDWP_TRACE_DATA("CreateString: send: objectID=" << str);
+    m_cmdParser->reply.WriteObjectID(jni, str);
+}
+
+//-----------------------------------------------------------------------------
+//CapabilitiesHandler----------------------------------------------------------
+
+inline static jboolean IsAdded(int value)
+{
+    return (value == 1) ? JNI_TRUE : JNI_FALSE;
+}
+
+void
+VirtualMachine::CapabilitiesHandler::Execute(JNIEnv *jni)
+    throw(AgentException)
+{
+    jdwpCapabilities caps = GetCapabilities();
+
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canWatchFieldModification));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canWatchFieldAccess));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetBytecodes));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetSyntheticAttribute));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetOwnedMonitorInfo));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetCurrentContendedMonitor));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetMonitorInfo));
+}
+
+//-----------------------------------------------------------------------------
+//ClassPathsHandler------------------------------------------------------------
+
+void
+VirtualMachine::ClassPathsHandler::WritePathStrings(char *str,
+        char pathSeparator) throw(AgentException)
+{
+    if (str == 0) {
+        m_cmdParser->reply.WriteInt(1);
+        m_cmdParser->reply.WriteString(str);
+    } else {
+        const size_t len = strlen(str);
+        jint pathCount = 0;
+        size_t i;
+
+        for (i = 0; i < len; i++) {
+            if (str[i] == pathSeparator) {
+                pathCount++;
+            }
+        }
+        pathCount++;
+
+        m_cmdParser->reply.WriteInt(pathCount);
+
+        char *path = str;
+        for (i = 0; i < len; i++) {
+            if (str[i] == pathSeparator) {
+                str[i] = '\0';
+                m_cmdParser->reply.WriteString(path);
+                path = &str[i+1];
+            }
+        }
+        m_cmdParser->reply.WriteString(path);
+    }
+}
+
+void
+VirtualMachine::ClassPathsHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    ClassManager &clsMgr = AgentBase::GetClassManager();
+
+    char *baseDir = clsMgr.GetProperty(jni, "user.dir");
+    AgentAutoFree dobj_baseDir(baseDir JDWP_FILE_LINE);
+
+    char *classPaths = clsMgr.GetProperty(jni, "java.class.path");
+    AgentAutoFree dobj_classPaths(classPaths JDWP_FILE_LINE);
+
+    char *bootClassPaths = clsMgr.GetProperty(jni, "vm.boot.class.path");
+    AgentAutoFree dobj_bootClassPaths(bootClassPaths JDWP_FILE_LINE);
+
+    char *pathSeparatorString = clsMgr.GetProperty(jni, "path.separator");
+    AgentAutoFree dobj_pathSeparatorString(pathSeparatorString JDWP_FILE_LINE);
+    char pathSeparator =
+        (pathSeparatorString == 0) ? ';' : pathSeparatorString[0];
+
+    JDWP_TRACE_DATA("ClassPaths: baseDir="
+        << JDWP_CHECK_NULL(baseDir));
+    JDWP_TRACE_DATA("ClassPaths: pathSeparatorString="
+        << JDWP_CHECK_NULL(pathSeparatorString));
+    JDWP_TRACE_DATA("ClassPaths: classPaths="
+        << JDWP_CHECK_NULL(classPaths));
+    JDWP_TRACE_DATA("ClassPaths: bootClassPaths="
+        << JDWP_CHECK_NULL(bootClassPaths));
+
+    m_cmdParser->reply.WriteString(baseDir);
+    WritePathStrings(classPaths, pathSeparator);
+    WritePathStrings(bootClassPaths, pathSeparator);
+}
+
+//-----------------------------------------------------------------------------
+//DisposeObjectsHandler--------------------------------------------------------
+
+void
+VirtualMachine::DisposeObjectsHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    jint refCount;
+    ObjectID objectID;
+    jint objCount = m_cmdParser->command.ReadInt();
+    JDWP_TRACE_DATA("DisposeObjects: dispose: objects=" << objCount);
+    for (jint i = 0; i < objCount; i++)
+    {
+        objectID = m_cmdParser->command.ReadRawObjectID();
+        refCount = m_cmdParser->command.ReadInt();
+        GetObjectManager().DisposeObject(jni, objectID, refCount);
+        JDWP_TRACE_DATA("DisposeObjects: object#=" << i 
+            << ", objectID=" << objectID);
+    }
+}
+
+//-----------------------------------------------------------------------------
+//HoldEventsHandler------------------------------------------------------------
+
+void
+VirtualMachine::HoldEventsHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    JDWP_TRACE_DATA("HoldEvents: hold events");
+    GetEventDispatcher().HoldEvents();
+}
+
+//-----------------------------------------------------------------------------
+//ReleaseEventsHandler---------------------------------------------------------
+
+void
+VirtualMachine::ReleaseEventsHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    JDWP_TRACE_DATA("ReleaseEvents: release events");
+    GetEventDispatcher().ReleaseEvents();
+}
+
+//-----------------------------------------------------------------------------
+//CapabilitiesNewHandler-------------------------------------------------------
+
+void
+VirtualMachine::CapabilitiesNewHandler::Execute(JNIEnv *jni)
+    throw(AgentException)
+{
+    jdwpCapabilities caps = GetCapabilities();
+
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canWatchFieldModification));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canWatchFieldAccess));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetBytecodes));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetSyntheticAttribute));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetOwnedMonitorInfo));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetCurrentContendedMonitor));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetMonitorInfo));
+    
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canRedefineClasses));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canAddMethod));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canUnrestrictedlyRedefineClasses));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canPopFrames));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canUseInstanceFilters));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canGetSourceDebugExtension));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canRequestVMDeathEvent));
+    m_cmdParser->reply.WriteBoolean(IsAdded(caps.canSetDefaultStratum));
+
+    for (int i = 0; i < 17; i++)
+        m_cmdParser->reply.WriteBoolean(JNI_FALSE);
+}
+
+//-----------------------------------------------------------------------------
+//RedefineClassesHandler-------------------------------------------------------
+
+class DAgentAutoFree {
+public:
+    DAgentAutoFree(unsigned char **ptr, size_t count) throw() : m_ptr(ptr) {m_count = count;}
+    ~DAgentAutoFree() throw()
+    {
+        MemoryManager &mm = AgentBase::GetMemoryManager();
+        if (m_ptr != 0)
+        {
+            for (jint i = 0; i < static_cast<long long>(m_count); i++)
+            {
+                if (m_ptr[i] != 0)
+                    mm.Free(m_ptr[i] JDWP_FILE_LINE);
+            }
+
+            mm.Free(m_ptr JDWP_FILE_LINE);
+        }
+    }
+private:
+    DAgentAutoFree(const DAgentAutoFree& other) : m_ptr(other.m_ptr) { }
+    const DAgentAutoFree& operator=(const DAgentAutoFree& r) {return *this;}
+
+    size_t m_count;
+    unsigned char **m_ptr;
+};
+
+void
+VirtualMachine::RedefineClassesHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    MemoryManager &mm = GetMemoryManager();
+
+    jint classCount = m_cmdParser->command.ReadInt();
+    JDWP_TRACE_DATA("RedefineClasses: received: classCount=" << classCount);
+
+    jvmtiClassDefinition *classDefs =
+        reinterpret_cast<jvmtiClassDefinition *>(mm.Allocate(sizeof(jvmtiClassDefinition)*classCount JDWP_FILE_LINE));
+    AgentAutoFree dobjDefs(classDefs JDWP_FILE_LINE);
+
+    {//to regulate an order of destructor jobs
+        jint i, j;
+
+        unsigned char **bytes =
+            reinterpret_cast<unsigned char **>(mm.Allocate(sizeof(unsigned char *)*classCount JDWP_FILE_LINE));
+        for (i = 0; i < classCount; i++) bytes[i] = 0;
+
+        DAgentAutoFree dobjDefs(bytes, classCount);
+
+        JDWP_TRACE_DATA("RedefineClasses: classes" << classCount);
+        for (i = 0; i < classCount; i++)
+        {
+            classDefs[i].klass = m_cmdParser->command.ReadReferenceTypeID(jni);
+            classDefs[i].class_byte_count = m_cmdParser->command.ReadInt();
+            bytes[i] =
+                reinterpret_cast<unsigned char *>(mm.Allocate(sizeof(unsigned char) * classDefs[i].class_byte_count JDWP_FILE_LINE));
+            for (j = 0; j < classDefs[i].class_byte_count; j++)
+                bytes[i][j] = m_cmdParser->command.ReadByte();
+            classDefs[i].class_bytes = bytes[i];
+#ifndef NDEBUG
+            if (JDWP_TRACE_ENABLED(LOG_KIND_DATA)) {    
+                jvmtiError err;
+                char* signature = 0;
+                JVMTI_TRACE(err, GetJvmtiEnv()->GetClassSignature(classDefs[i].klass, &signature, 0));
+                JvmtiAutoFree afcs(signature);
+                JDWP_TRACE_DATA("RedefineClasses: class#=" << i
+                    << ", refTypeID=" << classDefs[i].klass
+                    << ", class_byte_count=" << classDefs[i].class_byte_count 
+                    << ", signature=" << JDWP_CHECK_NULL(signature));
+            }
+#endif
+        }
+
+        jvmtiError err;
+        JVMTI_TRACE(err, GetJvmtiEnv()->RedefineClasses(classCount, classDefs));
+
+        if (err != JVMTI_ERROR_NONE)
+            throw AgentException(err);
+    }
+}
+
+//-----------------------------------------------------------------------------
+//SetDefaultStratumHandler-----------------------------------------------------
+
+void
+VirtualMachine::SetDefaultStratumHandler::Execute(JNIEnv *jni) throw(AgentException)
+{
+    // Note. The SetDefaultStratum handler is not implemented
+    // here because JDWP specs are not clear about this command.
+    JDWP_TRACE_DATA("SetDefaultStratumHandler: not implemented");
+    throw AgentException(JDWP_ERROR_NOT_IMPLEMENTED);
+}
+
+//-----------------------------------------------------------------------------
+//AllClassesWithGenericHandler-------------------------------------------------
+
+void
+VirtualMachine::AllClassesWithGenericHandler::Compose41Class(JNIEnv *jni_env,
+            jvmtiEnv* jvmti, jclass klass) throw (AgentException)
+{
+    jdwpTypeTag refTypeTag = GetClassManager().GetJdwpTypeTag(klass);
+
+    m_cmdParser->reply.WriteByte(refTypeTag);
+    m_cmdParser->reply.WriteReferenceTypeID(jni_env, klass);
+
+    char* signature = 0;
+    char* generic = 0;
+
+    jvmtiError err;
+    JVMTI_TRACE(err, jvmti->GetClassSignature(klass, &signature, &generic));
+
+    JvmtiAutoFree dobjs(signature);
+    JvmtiAutoFree dobjg(generic);
+
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    m_cmdParser->reply.WriteString(signature);
+
+    if (generic != 0)
+        m_cmdParser->reply.WriteString(generic);
+    else
+        m_cmdParser->reply.WriteString("");
+
+    jint status;
+    JVMTI_TRACE(err, jvmti->GetClassStatus(klass, &status));
+    if (err != JVMTI_ERROR_NONE)
+        throw AgentException(err);
+
+    // According to JVMTI spec ClassStatus flag for arrays and primitive classes must be zero
+    if (status == JVMTI_CLASS_STATUS_ARRAY) {
+        status = 0;
+    } else {
+        if ( status == JVMTI_CLASS_STATUS_PRIMITIVE ) {
+            status = 0;
+        }
+    }
+
+    m_cmdParser->reply.WriteInt(status);
+    JDWP_TRACE_DATA("AllClassesWithGeneric: typeTag=" << refTypeTag << ", refTypeID="
+         << klass << ", signature=" << JDWP_CHECK_NULL(signature) << ", generic=" 
+         << JDWP_CHECK_NULL(generic) << ", status=" << status);
+}
+
+//-----------------------------------------------------------------------------

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/commands/VirtualMachine.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,410 @@
+/*
+ * 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.6.2.1 $
+ */
+
+/**
+ * @file
+ * VirtualMachine.h
+ *
+ */
+
+#ifndef _VIRTUAL_MACHINE_H_
+#define _VIRTUAL_MACHINE_H_
+
+#include "AgentException.h"
+#include "CommandHandler.h"
+
+namespace jdwp {
+
+    /**
+     * The namespace includes declaration of the classes implementing commands
+     * from the VirtualMachine command set.
+     */
+    namespace VirtualMachine {
+        
+        /**
+         * The class implements the <code>Version</code> command from the
+         * VirtualMachine command set.
+         */
+        class VersionHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Version</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };
+
+        /**
+         * The class implements the <code>ClassesBySignature</code> command from the
+         * VirtualMachine command set.
+         */
+        class ClassesBySignatureHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>ClassesBySignature</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        private:
+            bool IsSignatureMatch(jclass klass, const char *signature)
+                throw(AgentException);
+
+        };//ClassesBySignatureHandler
+
+        /**
+         * The class implements the <code>AllClasses</code> command from the
+         * VirtualMachine command set.
+         */
+        class AllClassesHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>AllClasses</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+            /**
+             * Writes class-type tag, reference ID, signature and status
+             * to the reply packet.
+             *
+             * @param jni   - the JNI interface pointer
+             * @param jvmti - the JVMTI interface pointer
+             * @param klass - the Java class
+             */
+            virtual void Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti, jclass klass)
+                                            throw (AgentException);
+
+        };//AllClassesHandler
+
+        /**
+         * The class implements the <code>AllThreads</code> command from the
+         * VirtualMachine command set.
+         */
+        class AllThreadsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>AllThreads</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//AllThreadsHandler
+
+        /**
+         * The class implements the <code>TopLevelThreadGroups</code> command
+         * from the VirtualMachine command set.
+         */
+        class TopLevelThreadGroupsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>TopLevelThreadGroups</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//TopLevelThreadGroupsHandler
+
+        /**
+         * The class implements the <code>Dispose</code> command from the
+         * VirtualMachine command set.
+         */
+        class DisposeHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Dispose</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//DisposeHandler
+
+        /**
+         * The class implements the <code>IDSizes</code> command from the
+         * VirtualMachine command set.
+         */
+        class IDSizesHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>IDSizes</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//IDSizesHandler
+
+        /**
+         * The class implements the <code>Suspend</code> command from the
+         * VirtualMachine command set.
+         */
+        class SuspendHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Suspend</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//SuspendHandler
+
+        /**
+         * The class implements the <code>Resume</code> command from the
+         * VirtualMachine command set.
+         */
+        class ResumeHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Resume</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//ResumeHandler
+
+        /**
+         * The class implements the <code>Exit</code> command from the
+         * VirtualMachine command set.
+         */
+        class ExitHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Exit</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//ExitHandler
+
+        /**
+         * The class implements the <code>CreateString</code> command from the
+         * VirtualMachine command set.
+         */
+        class CreateStringHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>CreateString</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//CreateStringHandler
+
+        /**
+         * The class implements the <code>Capabilities</code> command from the
+         * VirtualMachine command set.
+         */
+        class CapabilitiesHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>Capabilities</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//CapabilitiesHandler
+
+        /**
+         * The class implements the <code>ClassPaths</code> command from the
+         * VirtualMachine command set.
+         */
+        class ClassPathsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>ClassPaths</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        private:
+            void WritePathStrings(char *str, char pathSeparator)
+                throw(AgentException);
+
+        };//ClassPathsHandler
+
+        /**
+         * The class implements the <code>DisposeObjects</code> command from the
+         * VirtualMachine command set.
+         */
+        class DisposeObjectsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>DisposeObjects</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//DisposeObjectsHandler
+
+        /**
+         * The class implements the <code>HoldEvents</code> command from the
+         * VirtualMachine command set.
+         */
+        class HoldEventsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>HoldEvents</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//HoldEventsHandler
+
+        /**
+         * The class implements the <code>ReleaseEvents</code> command from the
+         * VirtualMachine command set.
+         */
+        class ReleaseEventsHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>ReleaseEvents</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//ReleaseEventsHandler
+
+        /**
+         * The class implements the <code>CapabilitiesNew</code> command from the
+         * VirtualMachine command set.
+         */
+        class CapabilitiesNewHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>CapabilitiesNew</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//CapabilitiesNewHandler
+
+        /**
+         * The class implements the <code>RedefineClasses</code> command from the
+         * VirtualMachine command set.
+         */
+        class RedefineClassesHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>RedefineClasses</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//RedefineClassesHandler
+
+        /**
+         * The class implements the <code>SetDefaultStratum</code> command from the
+         * VirtualMachine command set.
+         */
+        class SetDefaultStratumHandler : public SyncCommandHandler {
+        protected:
+
+            /**
+             * Executes the <code>SetDefaultStratum</code> JDWP command for the
+             * VirtualMachine command set.
+             *
+             * @param jni - the JNI interface pointer
+             */
+            virtual void Execute(JNIEnv *jni) throw(AgentException);
+
+        };//SetDefaultStratumHandler
+
+        /**
+         * The class implements the <code>AllClassesWithGeneric</code> command
+         * from the VirtualMachine command set.
+         */
+        class AllClassesWithGenericHandler : public AllClassesHandler {
+        protected:
+
+            /**
+             * Writes a class-type tag, reference ID, signature, generic signature and status
+             * to the reply packet.
+             *
+             * @param jni   - the JNI interface pointer
+             * @param jvmti - the JVMTI interface pointer
+             * @param klass - Java class
+             */
+            virtual void Compose41Class(JNIEnv *jni, jvmtiEnv* jvmti, jclass klass)
+                                            throw (AgentException);
+
+        };//AllClassesWithGenericHandler
+
+    } // VirtualMachine
+
+} //jdwp
+
+#endif //_VIRTUAL_MACHINE_H_

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Agent.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Agent.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Agent.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/Agent.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,492 @@
+/*
+ * 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.25 $
+ */
+// Agent.cpp
+
+#include <cstdlib>
+#include <cstdio>
+
+#include "jvmti.h"
+
+#include "AgentEnv.h"
+#include "AgentBase.h"
+#include "MemoryManager.h"
+#include "AgentException.h"
+#include "LogManager.h"
+#include "Log.h"
+
+#include "ClassManager.h"
+#include "ObjectManager.h"
+#include "OptionParser.h"
+#include "ThreadManager.h"
+#include "RequestManager.h"
+#include "TransportManager.h"
+#include "PacketDispatcher.h"
+#include "EventDispatcher.h"
+
+using namespace jdwp;
+
+AgentEnv *AgentBase::m_agentEnv = 0;
+
+static const char* const AGENT_OPTIONS_ENVNAME = "JDWP_AGENT_OPTIONS";
+static const char* const AGENT_OPTIONS_PROPERTY = "jdwp.agent.options";
+
+//-----------------------------------------------------------------------------
+// static internal functions
+//-----------------------------------------------------------------------------
+
+static void Usage()
+{
+    std::fprintf(stdout,
+        "\nUsage: java -agentlib:agent=[help] |"
+        "\n\t[suspend=y|n][,transport=name][,address=addr]"
+        "\n\t[,server=y|n][,timeout=n]"
+#ifndef NDEBUG
+        "\n\t[,trace=none|all|log_kinds][,src=all|sources][,log=filepath]\n"
+#endif//NDEBUG
+        "\nWhere:"
+        "\n\thelp\t\tOutput this message"
+        "\n\tsuspend=y|n\tSuspend on start (default: y)"
+        "\n\ttransport=name\tName of transport to use for connection"
+        "\n\taddress=addr\tTransport address for connection"
+        "\n\tserver=y|n\tListen for or attach to debugger (default: n)"
+        "\n\ttimeout=n\tTime in ms to wait for connection (0-forever)"
+#ifndef NDEBUG
+        "\n\ttrace=log_kinds\tApplies filtering to log message kind (default: none)"
+        "\n\tsrc=sources\tApplies filtering to __FILE__ (default: all)"
+        "\n\tlog=filepath\tRedirect output into filepath\n"
+#endif//NDEBUG
+        "\nExample:"
+        "\n\tjava -agentlib:agent=transport=dt_socket,"
+        "address=localhost:7777,server=y\n"
+#ifndef NDEBUG
+        "\nExamples of tracing parameters:\n"
+        "\ttrace=all,log=jdwp.log\n"
+        "\t - traces all kinds of messages\n"
+        "\ttrace=MEM+MON,src=VirtualMachine.cpp,log=jdwp.log\n"
+        "\t - traces only MEM and MON messages from only one corresponding file\n"
+        "\nComplete list of log kinds is following:\n"
+        "\tMEM - memory alloc/free calls\n"
+        "\tMON - monitor enter/exit methods\n"
+        "\tMAP - reference/object id mapping\n"
+        "\tCMD - jdwp commands\n"
+        "\tPACK - jdwp packets\n"
+        "\tDATA - command data tracing\n"
+        "\tEVENT - jdwp events\n"
+        "\tPROG - program flow\n"
+        "\tUTIL - utilities messages\n"
+        "\tTHRD - thread\n"
+        "\tFUNC - function entry and exit\n"
+        "\tJVMTI - jvmti calls\n"
+        "\tLOG - debug messages\n"
+        "\tINFO - information and warning messages\n"
+        "\tERROR - error messages\n\n"
+#endif//NDEBUG
+    );
+}
+
+static void InitAgent(jvmtiEnv *jvmti, JNIEnv *jni)
+{
+    JDWP_TRACE_ENTRY("InitAgent(" << jvmti << "," << jni << ")");
+
+    JDWP_TRACE_PROG("InitAgent: init and start all modules");
+
+    //currentSessionID = 0;
+
+    try {
+        AgentBase::SetIsDead(false);
+        AgentBase::GetClassManager().Init(jni);
+        AgentBase::GetObjectManager().Init(jni);
+        AgentBase::GetThreadManager().Init(jni);
+        AgentBase::GetRequestManager().Init(jni);
+        AgentBase::GetEventDispatcher().Init(jni);
+        AgentBase::GetPacketDispatcher().Init(jni);
+
+        char* javaLibraryPath = 0;
+        jvmtiError err;
+        JVMTI_TRACE(err,
+            jvmti->GetSystemProperty("java.library.path", &javaLibraryPath));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to get system property: java.library.path")
+        }
+        JvmtiAutoFree afv(javaLibraryPath);
+        AgentBase::GetTransportManager().Init(
+            AgentBase::GetOptionParser().GetTransport(),
+            javaLibraryPath);
+
+        AgentBase::GetTransportManager().PrepareConnection(
+            AgentBase::GetOptionParser().GetAddress(),
+            AgentBase::GetOptionParser().GetServer(),
+            AgentBase::GetOptionParser().GetTimeout(),
+            AgentBase::GetOptionParser().GetTimeout()
+        );
+
+        AgentBase::GetEventDispatcher().Start(jni);
+        AgentBase::GetPacketDispatcher().Start(jni);
+    } catch (AgentException& e) {
+        JDWP_INFO("JDWP error: " << e.what() << " [" << e.ErrCode() << "]");
+        jni->FatalError("Unable to initialize agent");
+    }
+}
+
+//-----------------------------------------------------------------------------
+// event callbacks
+//-----------------------------------------------------------------------------
+
+static void JNICALL
+VMInit(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread)
+{
+    try {
+        JDWP_TRACE_ENTRY("VMInit(" << jvmti << ',' << jni << ',' << thread << ')');
+        jint ver = jni->GetVersion();
+        JDWP_LOG("JNI version: 0x" << hex << ver);
+
+        InitAgent(jvmti, jni);
+        RequestManager::HandleVMInit(jvmti, jni, thread);
+    } catch (AgentException& e) {
+        JDWP_INFO("JDWP error in VM_INIT: " << e.what() << " [" << e.ErrCode() << "]");
+    }
+}
+
+static void JNICALL
+VMDeath(jvmtiEnv *jvmti, JNIEnv *jni)
+{
+    try {
+        // don't print entry trace message after shutdown
+        {
+            JDWP_TRACE_ENTRY("VMDeath(" << jvmti << ',' << jni << ')');
+            RequestManager::HandleVMDeath(jvmti, jni);
+        }
+        AgentBase::SetIsDead(true);
+        AgentBase::GetPacketDispatcher().ShutdownAll(jni);
+    } catch (AgentException& e) {
+        JDWP_INFO("JDWP error in VM_DEATH: " << e.what() << " [" << e.ErrCode() << "]");
+    }
+}
+
+//-----------------------------------------------------------------------------
+// start-up and shutdown entry points
+//-----------------------------------------------------------------------------
+
+JNIEXPORT jint JNICALL 
+Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
+{
+
+//    static STDMemoryManager mm;
+    static VMMemoryManager mm;
+    static STDLogManager slm;
+    static AgentEnv env;
+
+    env.memoryManager = &mm;
+    env.logManager = &slm;
+    env.jvm = vm;
+    env.jvmti = 0;
+    env.isDead = false;
+    AgentBase::SetAgentEnv(&env);
+
+    jvmtiEnv *jvmti = 0;
+    jvmtiError err;
+
+    JDWP_TRACE_ENTRY("Agent_OnLoad(" << vm << "," << (void*)options << "," << reserved << ")");
+
+    // get JVMTI environment
+    {
+        jint ret =
+            (vm)->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_0);
+        if (ret != JNI_OK || jvmti == 0) {
+            JDWP_INFO("Unable to get JMVTI environment, return code = " << ret);
+            return JNI_ERR;
+        }
+        env.jvmti = jvmti;
+        jint version;
+        JVMTI_TRACE(err, jvmti->GetVersionNumber(&version));
+        JDWP_LOG("JVMTI version: 0x" << hex << version);
+    }
+
+    // parse agent options
+    try {
+        env.optionParser = new OptionParser();
+
+        // add options from environment variable and/or system property
+        {
+            char* envOptions = getenv(AGENT_OPTIONS_ENVNAME);
+            char* propOptions = 0;
+            jvmtiError err;
+
+            JVMTI_TRACE(err,
+                jvmti->GetSystemProperty(AGENT_OPTIONS_PROPERTY, &propOptions));
+            if (err != JVMTI_ERROR_NONE) {
+                JDWP_LOG("No system property: "
+                    << AGENT_OPTIONS_PROPERTY << ", err=" << err);
+                propOptions = 0;
+            }
+            JvmtiAutoFree af(propOptions);
+
+            if (envOptions != 0 || propOptions != 0) {
+                JDWP_INFO("Add options from: "
+                    << endl << "\tcommand line: " << JDWP_CHECK_NULL(options)
+                    << endl << "\tenvironment " << AGENT_OPTIONS_ENVNAME
+                    << ": " << JDWP_CHECK_NULL(envOptions)
+                    << endl << "\tproperty " << AGENT_OPTIONS_PROPERTY
+                    << ": " << JDWP_CHECK_NULL(propOptions)
+                );
+
+                size_t fullLength = ((options == 0) ? 0 : strlen(options) + 1)
+                    + ((propOptions == 0) ? 0 : strlen(propOptions) + 1)
+                    + ((envOptions == 0) ? 0 : strlen(envOptions) + 1);
+                char* fullOptions = static_cast<char*>
+                    (AgentBase::GetMemoryManager().Allocate(fullLength JDWP_FILE_LINE));
+                fullOptions[0] = '\0';
+                if (options != 0) {
+                    strcat(fullOptions, options);
+                }
+                if (envOptions != 0) {
+                    if (fullOptions[0] != '\0') {
+                        strcat(fullOptions, ",");
+                    }
+                    strcat(fullOptions, envOptions);
+                }
+                if (propOptions != 0) {
+                    if (fullOptions[0] != '\0') {
+                        strcat(fullOptions, ",");
+                    }
+                    strcat(fullOptions, propOptions);
+                }
+                options = fullOptions;
+                JDWP_INFO("Full options: " << JDWP_CHECK_NULL(options));
+            }
+
+            AgentBase::GetOptionParser().Parse(options);
+        }
+
+        // initialize LogManager module first
+        AgentBase::GetLogManager().Init(
+            AgentBase::GetOptionParser().GetLog(),
+            AgentBase::GetOptionParser().GetTraceKindFilter(),
+            AgentBase::GetOptionParser().GetTraceSrcFilter()
+        );
+
+        #ifndef NDEBUG
+        if (JDWP_TRACE_ENABLED(LOG_KIND_LOG)) {
+              int optCount = AgentBase::GetOptionParser().GetOptionCount();
+              JDWP_LOG("parsed " << optCount << " options:");
+              for (int k = 0; k < optCount; k++) {
+                  const char *name, *value;
+                  AgentBase::GetOptionParser().GetOptionByIndex(k, name, value);
+                  JDWP_LOG("[" << k << "]: " << JDWP_CHECK_NULL(name) << " = "
+                      << JDWP_CHECK_NULL(value));
+              }
+        }
+        #endif // NDEBUG
+
+        // exit if help option specified
+        if (AgentBase::GetOptionParser().GetHelp()) {
+            Usage();
+            JDWP_LOG("exit" << endl);
+            delete env.optionParser;
+            std::exit(0);
+        }
+
+        // check for required options
+        if (AgentBase::GetOptionParser().GetTransport() == 0) {
+            JDWP_INFO("JDWP error: No agent option specified: " << "transport");
+            return JNI_ERR;
+        }
+        if (!AgentBase::GetOptionParser().GetServer() 
+                && AgentBase::GetOptionParser().GetAddress() == 0) {
+            JDWP_INFO("JDWP error: No agent option specified: " << "address");
+            return JNI_ERR;
+        }
+
+        // create all other modules
+        env.classManager = new ClassManager();
+        env.objectManager = new ObjectManager();
+        env.threadManager = new ThreadManager();
+        env.requestManager = new RequestManager();
+        env.transportManager = new TransportManager();
+        env.packetDispatcher = new PacketDispatcher();
+        env.eventDispatcher = new EventDispatcher();
+    } catch (IllegalArgumentException&) {
+        JDWP_INFO("JDWP error: Bad agent options: " << options);
+        delete env.optionParser;
+        return JNI_ERR;
+    } catch (AgentException& e) {
+        JDWP_INFO("JDWP error: " << e.what() << " [" << e.ErrCode() << "]");
+        return JNI_ERR;
+    }
+
+#ifndef NDEBUG
+    // display system properties
+    if (JDWP_TRACE_ENABLED(LOG_KIND_LOG)) {
+        jint pCount;
+        char **properties = 0;
+
+        JVMTI_TRACE(err, jvmti->GetSystemProperties(&pCount, &properties));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to get system properties: " << err);
+        }
+        JvmtiAutoFree afp(properties);
+
+        JDWP_LOG("System properties:");
+        for (jint j = 0; j < pCount; j++) {
+            char *value = 0;
+            JvmtiAutoFree afj(properties[j]);
+            JVMTI_TRACE(err, jvmti->GetSystemProperty(properties[j], &value));
+            if (err != JVMTI_ERROR_NONE) {
+                JDWP_INFO("Unable to get system property: "
+                    << JDWP_CHECK_NULL(properties[j]));
+            }
+            JvmtiAutoFree afv(value);
+            JDWP_LOG("  " << j << ": " << JDWP_CHECK_NULL(properties[j])
+                << " = " << JDWP_CHECK_NULL(value));
+        }
+    }
+#endif // NDEBUG
+
+    // manage JVMTI and JDWP capabilities
+    {
+        jvmtiCapabilities caps;
+        memset(&caps, 0, sizeof(caps));
+
+        JVMTI_TRACE(err, jvmti->GetPotentialCapabilities(&caps));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to get potential capabilities: " << err);
+            return JNI_ERR;
+        }
+
+        // map directly into JDWP caps
+        env.caps.canWatchFieldModification =
+            caps.can_generate_field_modification_events;
+        env.caps.canWatchFieldAccess = caps.can_generate_field_access_events;
+        env.caps.canGetBytecodes = caps.can_get_bytecodes;
+        env.caps.canGetSyntheticAttribute = caps.can_get_synthetic_attribute;
+        env.caps.canGetOwnedMonitorInfo = caps.can_get_owned_monitor_info;
+        env.caps.canGetCurrentContendedMonitor =
+            caps.can_get_current_contended_monitor;
+        env.caps.canGetMonitorInfo = caps.can_get_monitor_info;
+        env.caps.canPopFrames = caps.can_pop_frame;
+        env.caps.canRedefineClasses = caps.can_redefine_classes;
+        env.caps.canGetSourceDebugExtension =
+            caps.can_get_source_debug_extension;
+
+        env.caps.canAddMethod = 0;
+        env.caps.canUnrestrictedlyRedefineClasses = 0;
+        env.caps.canUseInstanceFilters = 1;
+        env.caps.canRequestVMDeathEvent = 1;
+        env.caps.canSetDefaultStratum = 0;
+
+        // these caps should be added for full agent functionality
+        // caps.can_suspend = 1;
+        // caps.can_signal_thread = 1;
+        // caps.can_get_source_file_name = 1;
+        // caps.can_get_line_numbers = 1;
+        // caps.can_access_local_variables = 1;
+        // caps.can_generate_single_step_events = 1;
+        // caps.can_generate_exception_events = 1;
+        // caps.can_generate_frame_pop_events = 1;
+        // caps.can_generate_breakpoint_events = 1;
+        // caps.can_generate_method_entry_events = 1;
+        // caps.can_generate_method_exit_events = 1;
+        // caps.can_redefine_any_class = 1;
+
+        // these caps look unnecessary for JDWP agent
+        caps.can_tag_objects = 0;
+        caps.can_maintain_original_method_order = 0;
+        caps.can_redefine_any_class = 0;
+        caps.can_get_current_thread_cpu_time = 0;
+        caps.can_get_thread_cpu_time = 0;
+        caps.can_generate_all_class_hook_events = 0;
+        caps.can_generate_compiled_method_load_events = 0;
+        caps.can_generate_monitor_events = 0;
+        caps.can_generate_vm_object_alloc_events = 0;
+        caps.can_generate_native_method_bind_events = 0;
+        caps.can_generate_garbage_collection_events = 0;
+        caps.can_generate_object_free_events = 0;
+
+        JVMTI_TRACE(err, jvmti->AddCapabilities(&caps));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to add capabilities: " << err);
+            return JNI_ERR;
+        }
+    }
+
+    // set up initial event callbacks
+    {
+        jvmtiEventCallbacks ecbs;
+        memset(&ecbs, 0, sizeof(ecbs));
+
+        ecbs.VMInit = &VMInit;
+        ecbs.VMDeath = &VMDeath;
+
+        ecbs.Breakpoint = &RequestManager::HandleBreakpoint;
+        //ecbs.ClassLoad = &ClassLoad;
+        ecbs.ClassPrepare = &RequestManager::HandleClassPrepare;
+        ecbs.Exception = &RequestManager::HandleException;
+        //ecbs.ExceptionCatch = &ExceptionCatch;
+        ecbs.FieldAccess = &RequestManager::HandleFieldAccess;
+        ecbs.FieldModification = &RequestManager::HandleFieldModification;
+        ecbs.FramePop = &RequestManager::HandleFramePop;
+        ecbs.MethodEntry = &RequestManager::HandleMethodEntry;
+        ecbs.MethodExit = &RequestManager::HandleMethodExit;
+        ecbs.SingleStep = &RequestManager::HandleSingleStep;
+        ecbs.ThreadEnd = &RequestManager::HandleThreadEnd;
+        ecbs.ThreadStart = &RequestManager::HandleThreadStart;
+
+        JVMTI_TRACE(err,
+            jvmti->SetEventCallbacks(&ecbs, static_cast<jint>(sizeof(ecbs))));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to set event callbacks: " << err);
+            return JNI_ERR;
+        }
+
+        JVMTI_TRACE(err, jvmti->SetEventNotificationMode(JVMTI_ENABLE,
+            JVMTI_EVENT_VM_INIT, 0));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to enable VM_INIT event: " << err);
+            return JNI_ERR;
+        }
+        JVMTI_TRACE(err, jvmti->SetEventNotificationMode(JVMTI_ENABLE,
+            JVMTI_EVENT_VM_DEATH, 0));
+        if (err != JVMTI_ERROR_NONE) {
+            JDWP_INFO("Unable to enable VM_DEATH event: " << err);
+            return JNI_ERR;
+        }
+    }
+
+    return JNI_OK;
+}
+
+JNIEXPORT void JNICALL
+Agent_OnUnload(JavaVM *vm)
+{
+//    JDWP_TRACE_ENTRY("Agent_OnUnload(" << vm << ")");
+    
+    if (AgentBase::GetAgentEnv() != 0) {
+        delete &AgentBase::GetEventDispatcher();
+        delete &AgentBase::GetPacketDispatcher();
+        delete &AgentBase::GetTransportManager();
+        delete &AgentBase::GetRequestManager();
+        delete &AgentBase::GetThreadManager();
+        delete &AgentBase::GetObjectManager();
+        delete &AgentBase::GetClassManager();
+        delete &AgentBase::GetOptionParser();
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentAllocator.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentAllocator.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentAllocator.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentAllocator.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,85 @@
+/*
+ * 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.2.1 $
+ */
+
+/**
+ * @file
+ * AgentAllocator.h
+ *
+ */
+
+#ifndef _AGENT_ALLOCATOR_H_
+#define _AGENT_ALLOCATOR_H_
+
+#include <memory>
+
+namespace jdwp {
+
+    /**
+     * Agent allocator template.
+     */
+    template <class T>
+    class AgentAllocator : public allocator<T> {
+
+    public:
+
+        typedef T*        pointer;
+        typedef const T*  const_pointer;
+        typedef T&        reference;
+        typedef const T&  const_reference;
+        typedef T         value_type;
+        typedef size_t    size_type;
+        typedef ptrdiff_t difference_type;
+
+        /**
+         * Agent allocator rebind.
+         */
+
+        template <class U> struct rebind {
+            typedef AgentAllocator<U> other;
+        };
+
+        /**
+         * A constructor.
+         */
+        AgentAllocator() throw() { }
+
+        /**
+         * A copy constructor.
+         */
+        template <class U>
+        AgentAllocator(const AgentAllocator<U> &copy) throw() { }
+
+        pointer allocate(size_t n, const void* = 0) {
+            return reinterpret_cast<pointer>(
+                AgentBase::GetMemoryManager().Allocate(n * sizeof(T) JDWP_FILE_LINE));
+        }
+
+        void deallocate(pointer p, size_t n) {
+            AgentBase::GetMemoryManager().Free(p JDWP_FILE_LINE);
+        }
+
+    };
+
+} // namespace jdwp
+
+#endif // _AGENT_ALLOCATOR_H_

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentBase.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentBase.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentBase.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentBase.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,415 @@
+/*
+ * 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.8.2.1 $
+ */
+
+/**
+ * @file
+ * AgentBase.h
+ *
+ */
+
+#ifndef _AGENT_BASE_H_
+#define _AGENT_BASE_H_
+
+#include <cstdio>
+#include <cstdlib>
+#include <sstream>
+
+#include "AgentEnv.h"
+#include "MemoryManager.h"
+#include "Log.h"
+
+#ifdef NDEBUG
+#define CHECK_ENV(env)
+#else
+#define CHECK_ENV(env) { \
+    if (env == 0) { \
+        std::fprintf(stderr, \
+            "Bad environment: "# env"=%p\n", env); \
+        std::exit(1); \
+    } \
+}
+#endif // NDEBUG
+
+#ifdef NDEBUG
+#define CHECK_ENV_PTR(env, ptr)
+#else
+#define CHECK_ENV_PTR(env, ptr) { \
+    if (env == 0 || env->ptr == 0) { \
+        std::fprintf(stderr, \
+            "Bad environment: "# env"=%p, "# ptr"=%p\n", env, env->ptr); \
+        std::exit(1); \
+    } \
+}
+#endif // NDEBUG
+
+namespace jdwp {
+
+    /**
+     * The base agent class redefining new operators and deleting ones inside 
+     * the JDWP namespace.
+     *
+     * The class uses the <code>MemoryManager</code> object for allocation 
+     * and freeing all dynamic memory required by the agent.
+     */
+    class Allocatable {
+
+    public:
+
+        /**
+         * Redefined a new operator in the JDWP namespace.
+         */
+        void* operator new(size_t size);
+
+        /**
+         * Redefined a delete operator in the JDWP namespace.
+         */
+        void operator delete(void* ptr);
+
+        /**
+         * Redefined a new[] operator in the JDWP namespace.
+         */
+        void* operator new[](size_t size);
+
+        /**
+         * Redefined a delete[] operator in the JDWP namespace.
+         */
+        void operator delete[](void* ptr);
+    };
+
+    /**
+     * The base class providing a uniform access for key-agent objects.
+     * The class gives access to the following units:
+     * <ul>
+     *   <li>AgentEnv</li>
+     *   <li>MemoryManager</li>
+     *   <li>LogManager</li>
+     *   <li>OptionParser</li>
+     *   <li>ThreadManager</li>
+     *   <li>TransportManager</li>
+     *   <li>ObjectManager</li>
+     *   <li>ClassManager</li>
+     *   <li>PacketDispatcher</li>
+     *   <li>EventDispatcher</li>
+     *   <li>RequestManager</li>
+     *   <li>jvmtiEnv</li>
+     *   <li>JavaVM</li>
+     *   <li>JNIEnv</li>
+     *   <li>jdwpCapabilities</li>
+     * </ul>
+     * 
+     */
+    class AgentBase : public Allocatable {
+
+    public:
+
+        /**
+         * A constructor.
+         */
+        AgentBase() throw() {}
+
+        /**
+         * Stores agent environment in the agent base.
+         *
+         * @param env - the pointer to the agent environment
+         */
+        static void SetAgentEnv(AgentEnv *env) throw() {
+            m_agentEnv = env;
+        }
+
+        /**
+         * Gets agent environment from the agent base.
+         */
+        static AgentEnv* GetAgentEnv() throw() {
+            return m_agentEnv;
+        }
+
+        /**
+         * Gets the memory manager reference from the agent base.
+         */
+        static MemoryManager& GetMemoryManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, memoryManager);
+            return *m_agentEnv->memoryManager;
+        }
+
+        /**
+         * Gets a log manager reference from the agent base.
+         */
+        static LogManager& GetLogManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, logManager);
+            return *m_agentEnv->logManager;
+        }
+
+        /**
+         * Gets the option-parser reference from the agent base.
+         */
+        static OptionParser& GetOptionParser() throw() {
+            CHECK_ENV_PTR(m_agentEnv, optionParser);
+            return *m_agentEnv->optionParser;
+        }
+
+        /**
+         * Gets the thread-manager reference from the agent base.
+         */
+        static ThreadManager& GetThreadManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, threadManager);
+            return *m_agentEnv->threadManager;
+        }
+
+        /**
+         * Gets the transport-manager reference from the agent base.
+         */
+        static TransportManager& GetTransportManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, transportManager);
+            return *m_agentEnv->transportManager;
+        }
+
+        /**
+         * Gets the object-manager reference from the agent base.
+         */
+        static ObjectManager& GetObjectManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, objectManager);
+            return *m_agentEnv->objectManager;
+        }
+
+        /**
+         * Gets the class-manager reference from the agent base.
+         */
+        static ClassManager& GetClassManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, classManager);
+            return *m_agentEnv->classManager;
+        }
+
+        /**
+         * Gets the packet-dispatcher reference from the agent base.
+         */
+        static PacketDispatcher& GetPacketDispatcher() throw() {
+            CHECK_ENV_PTR(m_agentEnv, packetDispatcher);
+            return *m_agentEnv->packetDispatcher;
+        }
+
+        /**
+         * Gets the event-dispatcher reference from the agent base.
+         */
+        static EventDispatcher& GetEventDispatcher() throw() {
+            CHECK_ENV_PTR(m_agentEnv, eventDispatcher);
+            return *m_agentEnv->eventDispatcher;
+        }
+
+        /**
+         * Gets the request-manager reference from the agent base.
+         */
+        static RequestManager& GetRequestManager() throw() {
+            CHECK_ENV_PTR(m_agentEnv, requestManager);
+            return *m_agentEnv->requestManager;
+        }
+
+        /**
+         * Gets the pointer to JVMTI environment from the agent base.
+         */
+        static jvmtiEnv* GetJvmtiEnv() throw() {
+            CHECK_ENV_PTR(m_agentEnv, jvmti);
+            return m_agentEnv->jvmti;
+        }
+
+        /**
+         * Gets the pointer to the target VM from the agent base.
+         */
+        static JavaVM* GetJavaVM() throw() {
+            CHECK_ENV_PTR(m_agentEnv, jvm);
+            return m_agentEnv->jvm;
+        }
+
+        /**
+         * Gets the pointer to JNI environment from the agent base.
+         */
+        static JNIEnv* GetJniEnv() throw() {
+            JNIEnv *jniEnv = 0;
+            CHECK_ENV_PTR(m_agentEnv, jvm);
+            (m_agentEnv->jvm)->GetEnv((void **)&jniEnv, JNI_VERSION_1_4);
+            return jniEnv;
+        }
+
+        /**
+         * Gets JDWP capabilities from the agent base.
+         */
+        static jdwpCapabilities& GetCapabilities() throw() {
+            CHECK_ENV(m_agentEnv);
+            return m_agentEnv->caps;
+        }
+
+        /**
+         * Gets a dead status of the agent.
+         */
+        static bool IsDead() throw() {
+            CHECK_ENV(m_agentEnv);
+            return m_agentEnv->isDead;
+        }
+
+        /**
+         * Sets a dead status to the agent.
+         */
+        static void SetIsDead(bool isDead) throw() {
+            CHECK_ENV(m_agentEnv);
+            m_agentEnv->isDead = isDead;
+        }
+        
+    private:
+
+        AgentBase(const AgentBase& r) { }
+
+        const AgentBase& operator=(const AgentBase& r) {
+            return *this;
+        }
+
+        static AgentEnv *m_agentEnv;
+    };
+
+    inline void* Allocatable::operator new(size_t size) {
+        return AgentBase::GetMemoryManager().Allocate(size JDWP_FILE_LINE);
+    }
+
+    inline void Allocatable::operator delete(void* ptr) {
+        AgentBase::GetMemoryManager().Free(ptr JDWP_FILE_LINE);
+    }
+
+    inline void* Allocatable::operator new[](size_t size) {
+        return AgentBase::GetMemoryManager().Allocate(size JDWP_FILE_LINE);
+    }
+
+    inline void Allocatable::operator delete[](void* ptr) {
+        AgentBase::GetMemoryManager().Free(ptr JDWP_FILE_LINE);
+    }
+
+    /**
+     * The class provides automatic JVMTI memory freeing.
+     * A pointer to the previously allocated memory by JVMTI environment
+     * is stored in the JvmtiAutoFree constructor and automatically freed 
+     * in destructor.
+     */
+    class JvmtiAutoFree {
+
+    public:
+
+        /**
+         * A constructor.
+         * A pointer to the JVMTI memory is saved here.
+         */
+        JvmtiAutoFree(void* ptr) throw() : m_ptr(ptr) { }
+
+        /**
+         * A destructor.
+         * The saved pointer to the JVMTI memory is freed here.
+         */
+        ~JvmtiAutoFree() throw() {
+            if (m_ptr != 0) {
+                jvmtiError err;
+                JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->
+                    Deallocate(reinterpret_cast<unsigned char*>(m_ptr)));
+                JDWP_ASSERT(err==JVMTI_ERROR_NONE);
+            }
+        }
+
+    private:
+
+        JvmtiAutoFree(const JvmtiAutoFree& other) : m_ptr(other.m_ptr) { }
+        const JvmtiAutoFree& operator=(const JvmtiAutoFree& r) {
+            return *this;
+        }
+
+        void* m_ptr;
+    };
+
+    /**
+     * The class provides automatic agent memory deallocation.
+     * A pointer to the previously allocated memory by the agent MemoryManager
+     * is stored in the AgentAutoFree ctor and automatically freed in the dtor.
+     */
+    class AgentAutoFree {
+
+    public:
+
+        /**
+         * A constructor.
+         * A pointer to the agent memory is saved here.
+         */
+        AgentAutoFree(void* ptr JDWP_FILE_LINE_PAR) throw() : m_ptr(ptr) JDWP_FILE_LINE_INI { }
+
+        /**
+         * A destructor.
+         * The saved pointer to the agent memory is freed here.
+         */
+        ~AgentAutoFree() throw() {
+            if (m_ptr != 0) {
+                AgentBase::GetMemoryManager().Free(m_ptr JDWP_FILE_LINE_MPAR);
+            }
+        }
+
+    private:
+
+        AgentAutoFree(const AgentAutoFree& other) : m_ptr(other.m_ptr) { }
+        const AgentAutoFree& operator=(const AgentAutoFree& r) {
+            return *this;
+        }
+
+        JDWP_FILE_LINE_DECL;
+        void* m_ptr;
+    };
+
+#ifndef NDEBUG
+    
+    /**
+     * The given class is used in the debug mode only for tracing entry/exit of 
+     * agent functions.
+     */
+    class JdwpTraceEntry {
+
+    public:
+
+        /**
+         * A constructor.
+         * Traces method entry in the log.
+         */
+        JdwpTraceEntry(std::ostringstream& os, const char* file, int line, int kind)
+            : m_stream(os), m_file(file), m_line(line), m_kind(kind) {
+            AgentBase::GetLogManager().Trace(">> " + m_stream.str(), m_file, m_line, m_kind);
+        }
+
+        /**
+         * A destructor.
+         * Traces method exit in the log.
+         */
+        ~JdwpTraceEntry() {
+            AgentBase::GetLogManager().Trace("<< " + m_stream.str(), m_file, m_line, m_kind);
+        }
+
+    private:
+        std::ostringstream& m_stream;
+        const char* m_file;
+        int         m_line;
+        int         m_kind;
+    };
+#endif // NDEBUG
+
+} // namespace jdwp
+
+#endif // _AGENT_BASE_H_

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentEnv.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentEnv.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentEnv.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/agent/core/AgentEnv.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.4.2.1 $
+ */
+
+/**
+ * @file
+ * AgentEnv.h
+ *
+ */
+
+#ifndef _AGENT_ENV_H_
+#define _AGENT_ENV_H_
+
+#include "jni.h"
+#include "jvmti.h"
+#include "jdwpTypes.h"
+
+namespace jdwp {
+
+    class MemoryManager;
+    class LogManager;
+    class OptionParser;
+    class ClassManager;
+    class ObjectManager;
+    class ThreadManager;
+    class TransportManager;
+    class PacketDispatcher;
+    class EventDispatcher;
+    class RequestManager;
+
+    /**
+     * Agent-environment structure containing all objects participating in
+     * the JDWP realization.
+     */
+    struct AgentEnv {
+
+        MemoryManager *memoryManager;
+        LogManager *logManager;
+        OptionParser *optionParser;
+        ClassManager *classManager;
+        ObjectManager *objectManager;
+        ThreadManager *threadManager;
+        TransportManager *transportManager;
+        PacketDispatcher *packetDispatcher;
+        EventDispatcher *eventDispatcher;
+        RequestManager *requestManager;
+
+        jvmtiEnv *jvmti;
+        JavaVM *jvm;
+
+        jdwpCapabilities caps;
+        bool volatile isDead;
+    };
+}
+
+#endif // _AGENT_ENV_H_

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



Mime
View raw message