Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 31938 invoked from network); 7 May 2008 12:33:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 May 2008 12:33:54 -0000 Received: (qmail 78567 invoked by uid 500); 7 May 2008 12:33:56 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 78548 invoked by uid 500); 7 May 2008 12:33:56 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 78537 invoked by uid 99); 7 May 2008 12:33:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 05:33:56 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 12:33:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0E59B2388A27; Wed, 7 May 2008 05:33:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r654082 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp: common/agent/commands/ common/agent/core/ common/generic/ common/transport/common/ common/transport/dt_socket/ unix/agent/ unix/agent/core/ unix/trans... Date: Wed, 07 May 2008 12:33:29 -0000 To: commits@harmony.apache.org From: lvjing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080507123332.0E59B2388A27@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lvjing Date: Wed May 7 05:33:27 2008 New Revision: 654082 URL: http://svn.apache.org/viewvc?rev=654082&view=rev Log: Maybe caused by some eclipse/sublipse bugs, I was committing the wrong code. Revert and apologize for the in-convenience that casued. Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp Wed May 7 05:33:27 2008 @@ -82,8 +82,8 @@ // Can be: JVMTI_ERROR_INVALID_CLASS, JVMTI_ERROR_NULL_POINTER throw AgentException(err); } - // jint const JVMTI_CLASS_STATUS_PREPARED = 0x2 ; - if ( (status & 0x2) == 0 ) { + jint const JVMTI_CLASS_STATUS_PREPARED = 0x2; + if ( (status & JVMTI_CLASS_STATUS_PREPARED) == 0 ) { throw AgentException(JDWP_ERROR_CLASS_NOT_PREPARED); } Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp Wed May 7 05:33:27 2008 @@ -249,7 +249,7 @@ JDWP_TRACE_MAP("## DisableCollection: NewGlobalRef returned NULL"); throw OutOfMemoryException(); } - JNIEnvPtr->DeleteWeakGlobalRef((jweak)jvmObject); + JNIEnvPtr->DeleteWeakGlobalRef(jvmObject); objectIDItem->mapObjectIDItem.globalRefKind = NORMAL_GLOBAL_REF; objectIDItem->mapObjectIDItem.jvmObject = newGlobRef; } // synchronized block: objectIDTableLock @@ -431,7 +431,7 @@ if (objectIDItem->mapObjectIDItem.globalRefKind == NORMAL_GLOBAL_REF) { JNIEnvPtr->DeleteGlobalRef(jvmObject); } else { - JNIEnvPtr->DeleteWeakGlobalRef((jweak)jvmObject); + JNIEnvPtr->DeleteWeakGlobalRef(jvmObject); } objectIDItem->objectID = FREE_OBJECTID_SIGN; objectIDItem->nextFreeObjectIDItem = m_freeObjectIDItems[idx]; @@ -503,7 +503,7 @@ if (objectIDItem->mapObjectIDItem.globalRefKind == NORMAL_GLOBAL_REF) { JNIEnvPtr->DeleteGlobalRef(objectIDItem->mapObjectIDItem.jvmObject); } else { - JNIEnvPtr->DeleteWeakGlobalRef((jweak)objectIDItem->mapObjectIDItem.jvmObject); + JNIEnvPtr->DeleteWeakGlobalRef(objectIDItem->mapObjectIDItem.jvmObject); } } objectIDItem++; @@ -643,7 +643,7 @@ for (size_t idx = 0; idx < HASH_TABLE_SIZE; idx++) { if (m_refTypeIDTable[idx]) { for (size_t item = 0; item < m_refTypeIDTableUsed[idx]; item++) - JNIEnvPtr->DeleteWeakGlobalRef((jweak)m_refTypeIDTable[idx][item]); + JNIEnvPtr->DeleteWeakGlobalRef(m_refTypeIDTable[idx][item]); GetMemoryManager().Free(m_refTypeIDTable[idx] JDWP_FILE_LINE); m_refTypeIDTable[idx] = NULL; m_refTypeIDTableUsed[idx] = m_refTypeIDTableSize[idx] = 0; @@ -925,7 +925,7 @@ threadFramesItem++; continue; } - JNIEnvPtr->DeleteWeakGlobalRef((jweak)threadFramesItem->jvmThread); + JNIEnvPtr->DeleteWeakGlobalRef(threadFramesItem->jvmThread); threadFramesItem++; } AgentBase::GetMemoryManager().Free(m_frameIDTable JDWP_FILE_LINE); Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h Wed May 7 05:33:27 2008 @@ -38,10 +38,6 @@ #include "jdwpTypes.h" #include "AgentMonitor.h" -#if defined(ZOS) -#include -#endif - namespace jdwp { // hash table parameters Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp Wed May 7 05:33:27 2008 @@ -23,11 +23,8 @@ // TransportManager.cpp // -#ifndef USING_VMI -#define USING_VMI #include "TransportManager.h" - using namespace jdwp; static void* @@ -66,13 +63,12 @@ GetMemoryManager().Free(m_address JDWP_FILE_LINE); } if (m_loadedLib != 0) { - PORT_ACCESS_FROM_JAVAVM(GetJavaVM()); - //jdwpTransport_UnLoad_Type UnloadFunc = reinterpret_cast - // (GetProcAddress(m_loadedLib, unLoadDecFuncName)); - j9sl_close_shared_library ((UDATA)m_loadedLib); - //if ((UnloadFunc != 0) && (m_env != 0)) { - // (UnloadFunc) (&m_env); - //} + jdwpTransport_UnLoad_Type UnloadFunc = reinterpret_cast + (GetProcAddress(m_loadedLib, unLoadDecFuncName)); + if ((UnloadFunc != 0) && (m_env != 0)) { + (UnloadFunc) (&m_env); + } + FreeLibrary(m_loadedLib); } } //TransportManager::~TransportManager() @@ -124,10 +120,8 @@ throw TransportException(JDWP_ERROR_TRANSPORT_LOAD, JDWPTRANSPORT_ERROR_NONE, m_lastErrorMessage); } - PORT_ACCESS_FROM_JAVAVM(GetJavaVM()); - - jdwpTransport_OnLoad_t transportOnLoad; - UDATA ret = j9sl_lookup_name((UDATA)m_loadedLib, (char*) onLoadDecFuncName, (UDATA*) &transportOnLoad, "ILLIL"); + jdwpTransport_OnLoad_t transportOnLoad = reinterpret_cast + (GetProcAddress(m_loadedLib, onLoadDecFuncName)); if (transportOnLoad == 0) { if (m_lastErrorMessage != 0) { GetMemoryManager().Free(m_lastErrorMessage JDWP_FILE_LINE); @@ -139,8 +133,7 @@ JDWP_ERROR(onLoadDecFuncName << " function not found in " << transportName); throw TransportException(JDWP_ERROR_TRANSPORT_INIT, JDWPTRANSPORT_ERROR_NONE, m_lastErrorMessage); } - - jint res = (*transportOnLoad)(GetJavaVM(), &callback, JDWPTRANSPORT_VERSION_1_0, &m_env); + jint res = (*transportOnLoad)(GetJavaVM(), &callback, JDWPTRANSPORT_VERSION_1_0, &m_env); if (res == JNI_ENOMEM) { if (m_lastErrorMessage != 0) { GetMemoryManager().Free(m_lastErrorMessage JDWP_FILE_LINE); @@ -358,47 +351,3 @@ << " cmd=" << (int)(packet->type.cmd.cmd)); } } // TransportManager::TracePacket() - -LoadedLibraryHandler TransportManager::LoadTransport(const char* dirName, const char* transportName) -{ -// JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(GetJavaVM()); - - JDWP_TRACE_ENTRY("LoadTransport(" << JDWP_CHECK_NULL(dirName) << ',' << JDWP_CHECK_NULL(transportName) << ')'); - - JDWP_ASSERT(transportName != 0); - char* transportFullName = 0; -#ifdef WIN32 - if (dirName == 0) { - size_t length = strlen(transportName) + 5; - transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); - sprintf(transportFullName, "%s.dll", transportName); - } else { - size_t length = strlen(dirName) + strlen(transportName) + 6; - transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); - sprintf(transportFullName, "%s\\%s.dll", dirName, transportName); - } -#else - if (dirName == 0) { - size_t length = strlen(transportName) + 7; - transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); - sprintf(transportFullName, "lib%s.so", transportName); - } else { - size_t length = strlen(dirName) + strlen(transportName) + 8; - transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); - sprintf(transportFullName, "%s/lib%s.so", dirName, transportName); - } -#endif -// AgentAutoFree afv(transportFullName JDWP_FILE_LINE); - UDATA res; - UDATA ret = j9sl_open_shared_library(transportFullName,(UDATA *)&res, FALSE); - if (ret != 0) { - JDWP_TRACE_PROG("LoadTransport: loading library " << transportFullName << " failed (error code: " << j9error_last_error_message() << ")"); - //JDWP_TRACE_PROG("LoadTransport: loading library " << transportFullName << " failed (error code: " << GetLastTransportError() << ")"); - } else { - JDWP_TRACE_PROG("LoadTransport: transport library " << transportFullName << " loaded"); - } - return (LoadedLibraryHandler)res; -} - -#endif Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h Wed May 7 05:33:27 2008 @@ -30,14 +30,11 @@ #ifndef _TRANSPORT_MANAGER_H_ #define _TRANSPORT_MANAGER_H_ -#include "TransportManager_pd.h" #include "jdwpTransport.h" #include "AgentBase.h" #include "AgentException.h" #include "Log.h" -#include "vmi.h" -#include "j9thread.h" -#include "j9port.h" +#include "TransportManager_pd.h" namespace jdwp { Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h Wed May 7 05:33:27 2008 @@ -83,6 +83,8 @@ JDWP_COMMAND_VM_REDEFINE_CLASSES = 18, JDWP_COMMAND_VM_SET_DEFAULT_STRATUM = 19, JDWP_COMMAND_VM_ALL_CLASSES_WITH_GENERIC= 20, + //New commands for Java 6 + JDWP_COMMAND_VM_INSTANCE_COUNTS = 21, /* Commands ReferenceType */ JDWP_COMMAND_RT_SIGNATURE = 1, @@ -100,6 +102,10 @@ JDWP_COMMAND_RT_SIGNATURE_WITH_GENERIC = 13, JDWP_COMMAND_RT_FIELDS_WITH_GENERIC = 14, JDWP_COMMAND_RT_METHODS_WITH_GENERIC = 15, + //New commands for Java 6 + JDWP_COMMAND_RT_INSTANCES = 16, + JDWP_COMMAND_RT_CLASS_FILE_VERSION = 17, + JDWP_COMMAND_RT_CONSTANT_POOL = 18, /* Commands ClassType */ JDWP_COMMAND_CT_SUPERCLASS = 1, @@ -126,6 +132,8 @@ JDWP_COMMAND_OR_DISABLE_COLLECTION = 7, JDWP_COMMAND_OR_ENABLE_COLLECTION = 8, JDWP_COMMAND_OR_IS_COLLECTED = 9, + // New commands for Java 6 + JDWP_COMMAND_OR_REFERRING_OBJECTS = 10, /* Commands StringReference */ JDWP_COMMAND_SR_VALUE = 1, @@ -143,6 +151,9 @@ JDWP_COMMAND_TR_STOP = 10, JDWP_COMMAND_TR_INTERRUPT = 11, JDWP_COMMAND_TR_SUSPEND_COUNT = 12, + // New command for Java 6 + JDWP_COMMAND_TR_OWNED_MONITORS_STACK_DEPTH = 13, + JDWP_COMMAND_TR_FORCE_EARLY_RETURN = 14, /* Commands ThreadGroupReference */ JDWP_COMMAND_TGR_NAME = 1, @@ -259,7 +270,13 @@ JDWP_EVENT_VM_INIT = 90, JDWP_EVENT_VM_START = JDWP_EVENT_VM_INIT, JDWP_EVENT_VM_DEATH = 99, - JDWP_EVENT_VM_DISCONNECTED = 100 + JDWP_EVENT_VM_DISCONNECTED = 100, + // New EventKind constants for Java 6 + JDWP_EVENT_METHOD_EXIT_WITH_RETURN_VALUE = 42, + JDWP_EVENT_MONITOR_CONTENDED_ENTER = 43, + JDWP_EVENT_MONITOR_CONTENDED_ENTERED = 44, + JDWP_EVENT_MONITOR_WAIT = 45, + JDWP_EVENT_MONITOR_WAITED = 46 } jdwpEventKind; /* EventRequest/ModifierKind Constants */ @@ -275,7 +292,9 @@ JDWP_MODIFIER_EXCEPTION_ONLY = 8, JDWP_MODIFIER_FIELD_ONLY = 9, JDWP_MODIFIER_STEP = 10, - JDWP_MODIFIER_INSTANCE_ONLY = 11 + JDWP_MODIFIER_INSTANCE_ONLY = 11, + // New ModifierKind constants for Java 6 + JDWP_MODIFIER_SOURCE_NAME_MATCH = 12 } jdwpRequestModifier; /* ThreadStatus Constants */ Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp Wed May 7 05:33:27 2008 @@ -20,35 +20,14 @@ * @author Viacheslav G. Rybalov * @version $Revision: 1.6 $ */ -#include "SocketTransport.h" #include "SocketTransport_pd.h" -#include "j9thread.h" -#define THREAD_ACCESS_FROM_ENV(jniEnv)\ - VMInterface *threadPrivateVMI = VMI_GetVMIFromJNIEnv(jniEnv);\ - J9PortLibrary *privatePortLibForThread = (*threadPrivateVMI)->GetPortLibrary(threadPrivateVMI);\ - J9ThreadLibrary *privateThreadLibrary = privatePortLibForThread->port_get_thread_library(privatePortLibForThread) -void (*LastTransportError::m_free)(void *buffer) = 0; - -static inline ThreadId_t -_GetCurrentThreadId(JNIEnv* jni) -{ - // THREAD_ACCESS_FROM_ENV(jni); - ThreadId_t tid ; - j9thread_attach(&tid); - return tid; -} // GetCurrentThreadId() - -static inline bool ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2) -{ - return (treadId1 == treadId2); -} // ThreadId_equal() +void (*LastTransportError::m_free)(void *buffer) = 0; -LastTransportError::LastTransportError(JNIEnv *jni, const char* messagePtr, int errorStatus, +LastTransportError::LastTransportError(const char* messagePtr, int errorStatus, void* (*alloc)(jint numBytes), void (*free)(void *buffer)) { - m_jni = jni; - m_treadId = _GetCurrentThreadId(m_jni); + m_treadId = GetCurrentThreadId(); m_lastErrorMessage = messagePtr; m_lastErrorMessagePrefix = ""; m_lastErrorStatus = errorStatus; @@ -86,15 +65,14 @@ jdwpTransportError LastTransportError::insertError(const char* messagePtr, int errorStatus) { - - if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { + if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { m_lastErrorMessage = messagePtr; m_lastErrorStatus = errorStatus; m_lastErrorMessagePrefix = ""; } else if (m_next != 0) { return m_next->insertError(messagePtr, errorStatus); } else { - m_next = new(m_alloc, m_free) LastTransportError(m_jni, messagePtr, errorStatus, m_alloc, m_free); + m_next = new(m_alloc, m_free) LastTransportError(messagePtr, errorStatus, m_alloc, m_free); if (m_next == 0) { return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } @@ -105,7 +83,7 @@ jdwpTransportError LastTransportError::addErrorMessagePrefix(const char* prefixPtr) { - if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { + if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { m_lastErrorMessagePrefix = (prefixPtr == 0 ? "" : prefixPtr); } else if (m_next != 0) { return m_next->addErrorMessagePrefix(prefixPtr); @@ -116,7 +94,7 @@ int LastTransportError::GetLastErrorStatus() { - if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { + if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { return m_lastErrorStatus; } else if (m_next != 0) { return m_next->GetLastErrorStatus(); @@ -127,7 +105,7 @@ char* LastTransportError::GetLastErrorMessage() { - if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { + if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { char buf[32]; sprintf(buf, "%d", m_lastErrorStatus); Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h Wed May 7 05:33:27 2008 @@ -31,11 +31,6 @@ #define _LASTTRANSPORTERROR_H #include "SocketTransport_pd.h" -#include "jni.h" -#include "jvmti.h" -#include "j9thread.h" -#include "jdwpTransport.h" -typedef j9thread_t ThreadId_t; /** * The given class is a container for message and status code of the last @@ -55,7 +50,7 @@ * @param free - the pointer to the function deallocating the memory * area */ - LastTransportError(JNIEnv *jni, const char* messagePtr, int errorStatus, + LastTransportError(const char* messagePtr, int errorStatus, void* (*alloc)(jint numBytes), void (*free)(void *buffer)); /** @@ -107,7 +102,6 @@ void operator delete(void* address, void* (*alloc)(jint numBytes), void (*free)(void *buffer)); private: - JNIEnv* m_jni; ThreadId_t m_treadId; // the thread Id const char* m_lastErrorMessage; // diagnostics for the last failed operation const char* m_lastErrorMessagePrefix; // diagnostics prefix for the last failed operation Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp Wed May 7 05:33:27 2008 @@ -28,136 +28,7 @@ * Main module. */ -#ifndef USING_VMI -#define USING_VMI #include "SocketTransport_pd.h" -#include "j9socket.h" -#include "j9sock.h" - -typedef struct PortlibPTBuffers_struct -{ - struct PortlibPTBuffers_struct *next; /**< Next per thread buffer */ - struct PortlibPTBuffers_struct *previous; /**< Previous per thread buffer */ - I_32 platformErrorCode; /**< error code as reported by the OS */ - I_32 portableErrorCode; /**< error code translated to portable format by application */ - char *errorMessageBuffer; /**< last saved error message, either customized or from OS */ - U_32 errorMessageBufferSize; /**< error message buffer size */ - I_32 reportedErrorCode; /**< last reported error code */ - char *reportedMessageBuffer; /**< last reported error message, either customized or from OS */ - U_32 reportedMessageBufferSize; /**< reported message buffer size */ - j9fdset_t fdset; /**< file descriptor set */ - j9addrinfo_struct addr_info_hints; -} PortlibPTBuffers_struct; - -typedef struct PortlibPTBuffers_struct *PortlibPTBuffers_t; - -extern void *VMCALL j9port_tls_get (struct HyPortLibrary *portLibrary); - - -/** - * Returns the error status for the last failed operation. - */ -static int -GetLastErrorStatus(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - PORT_ACCESS_FROM_JAVAVM(ienv->jvm); - return j9error_last_error_number(); -} // GetLastErrorStatus - -/** - * Retrieves the number of milliseconds, substitute for the corresponding Win32 - * function. - */ -static long -GetTickCount(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - PORT_ACCESS_FROM_JAVAVM(ienv->jvm); - return (long)j9time_current_time_millis(); -} // GetTickCount - -/** - * Initializes critical section lock objects. - */ -static inline void -InitializeCriticalSections(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - j9thread_attach(NULL); - - UDATA flags = 0; - if (j9thread_monitor_init(&(ienv->readLock), 1) != 0) { - printf("initial error\n"); - } - - if (j9thread_monitor_init(&(ienv->sendLock), 1) != 0) { - printf("initial error\n"); - } - -} //InitializeCriticalSections() - -/** - * Releases all resources used by critical-section lock objects. - */ -static inline void -DeleteCriticalSections(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - - j9thread_attach(NULL); - j9thread_monitor_destroy(ienv->readLock); - j9thread_monitor_destroy(ienv->sendLock); -} //DeleteCriticalSections() - -/** - * Waits for ownership of the send critical-section object. - */ -static inline void -EnterCriticalSendSection(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - - j9thread_attach(NULL); - j9thread_monitor_enter(ienv->sendLock); -} //EnterCriticalSendSection() - -/** - * Waits for ownership of the read critical-section object. - */ -static inline void -EnterCriticalReadSection(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - - j9thread_attach(NULL); - j9thread_monitor_enter(ienv->readLock); -} //EnterCriticalReadSection() - -/** - * Releases ownership of the read critical-section object. - */ -static inline void -LeaveCriticalReadSection(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - - j9thread_attach(NULL); - j9thread_monitor_exit(ienv->readLock); -} //LeaveCriticalReadSection() - -/** - * Releases ownership of the send critical-section object. - */ -static inline void -LeaveCriticalSendSection(jdwpTransportEnv* env) -{ - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - - j9thread_attach(NULL); - j9thread_monitor_exit(ienv->sendLock); -} //LeaveCriticalSendSection() - /** * This function sets into internalEnv struct message and status code of last transport error @@ -169,9 +40,7 @@ if (ienv->lastError != 0) { ienv->lastError->insertError(messagePtr, errorStatus); } else { - JNIEnv *jni; - ienv->jvm->GetEnv((void **)&jni, JNI_VERSION_1_4); - ienv->lastError = new(ienv->alloc, ienv->free) LastTransportError(jni, messagePtr, errorStatus, ienv->alloc, ienv->free); + ienv->lastError = new(ienv->alloc, ienv->free) LastTransportError(messagePtr, errorStatus, ienv->alloc, ienv->free); } return; } // SetLastTranError @@ -196,72 +65,13 @@ static const jint cycle = 1000; // wait cycle in milliseconds /** - * This function enable/disables socket blocking mode - */ -static bool -SetSocketBlockingMode(jdwpTransportEnv* env, j9socket_t sckt, bool isBlocked) -{ - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - - jint ret = j9sock_set_nonblocking(sckt, isBlocked ? FALSE : TRUE); - if (ret != 0){ - SetLastTranError(env, "socket error", GetLastErrorStatus(env)); - return false; - } - return true; - -} // SetSocketBlockingMode() - -/** * This function is used to determine the read status of socket (in terms of select function). * The function avoids absolutely blocking select */ static jdwpTransportError -SelectRead(jdwpTransportEnv* env, j9socket_t sckt, jlong deadline = 0) { - internalEnv* ienv = (internalEnv*)env->functions->reserved1; - PORT_ACCESS_FROM_JAVAVM(ienv->jvm); -/* -#ifdef WIN32 - SOCKET socket = sckt->ipv4; -#else - SOCKET socket = sckt->sock; -#endif - deadline = deadline == 0 ? 1000 : deadline; - if (deadline >= 0) { - TIMEVAL tv = {(long)(deadline / 1000), (long)(deadline % 1000)}; - fd_set fdread; - FD_ZERO(&fdread); - FD_SET(socket, &fdread); +SelectRead(jdwpTransportEnv* env, SOCKET sckt, jlong deadline = 0) { - int ret = select((int)(socket) + 1, &fdread,NULL, NULL, &tv); - if (ret < 0) { - int err = GetLastErrorStatus(env); - // ignore signal interruption - if (err != SOCKET_ERROR_EINTR) { - SetLastTranError(env, "socket error", err); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - } - if ((ret > 0) && (FD_ISSET(socket, &fdread))) { - return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred - } - } - SetLastTranError(env, "timeout occurred", 0); - return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred -*/ - jint ret = j9sock_select_read(sckt, (I_32) deadline / 1000 , (I_32) deadline % 1000, FALSE); - if (ret == 1){ - return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred - } - if (ret != J9PORT_ERROR_SOCKET_TIMEOUT){ - SetLastTranError(env, "socket error", ret); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - SetLastTranError(env, "timeout occurred", 0); - return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred - -/* jlong currentTimeout = cycle; + jlong currentTimeout = cycle; while ((deadline == 0) || ((currentTimeout = (deadline - GetTickCount())) > 0)) { currentTimeout = currentTimeout < cycle ? currentTimeout : cycle; TIMEVAL tv = {(long)(currentTimeout / 1000), (long)(currentTimeout % 1000)}; @@ -271,7 +81,7 @@ int ret = select((int)sckt + 1, &fdread, NULL, NULL, &tv); if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(env); + int err = GetLastErrorStatus(); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "socket error", err); @@ -284,7 +94,6 @@ } SetLastTranError(env, "timeout occurred", 0); return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred -*/ } // SelectRead /** @@ -292,98 +101,43 @@ * The function avoids absolutely blocking select */ static jdwpTransportError -SelectSend(jdwpTransportEnv* env, j9socket_t sckt, jlong deadline = 0) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - - j9fdset_struct j9fdSet; - - I_32 secTime = (long)(deadline / 1000); - I_32 uTime = (long)(deadline % 1000); +SelectSend(jdwpTransportEnv* env, SOCKET sckt, jlong deadline = 0) { - j9timeval_struct timeval; - - j9sock_fdset_zero(&j9fdSet); - j9sock_fdset_set(sckt,&j9fdSet); - - int ret = j9sock_timeval_init(secTime,uTime,&timeval); - - ret = j9sock_select(j9sock_fdset_size(sckt),NULL,&j9fdSet,NULL,&timeval); - - if (ret > 0){ - return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred - } - if (ret != J9PORT_ERROR_SOCKET_TIMEOUT){ - SetLastTranError(env, "socket error", ret); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - SetLastTranError(env, "timeout occurred", 0); - return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred - - //jlong currentTimeout = cycle; - -// leave a workaround here, wait for new portlib for select APIs -/* #ifdef WIN32 - SOCKET socket = sckt->ipv4; -#else - SOCKET socket = sckt->sock; -#endif - deadline = deadline == 0 ? 100 : deadline; - if (deadline >= 0) { - TIMEVAL tv = {(long)(deadline / 1000), (long)(deadline % 1000)}; + jlong currentTimeout = cycle; + while ((deadline == 0) || ((currentTimeout = (deadline - GetTickCount())) > 0)) { + currentTimeout = currentTimeout < cycle ? currentTimeout : cycle; + TIMEVAL tv = {(long)(currentTimeout / 1000), (long)(currentTimeout % 1000)}; fd_set fdwrite; FD_ZERO(&fdwrite); - FD_SET(socket, &fdwrite); + FD_SET(sckt, &fdwrite); - int ret = select((int)(socket) + 1, NULL, &fdwrite, NULL, &tv); - if (ret < 0) { - int err = GetLastErrorStatus(env); + int ret = select((int)sckt + 1, NULL, &fdwrite, NULL, &tv); + if (ret == SOCKET_ERROR) { + int err = GetLastErrorStatus(); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "socket error", err); return JDWPTRANSPORT_ERROR_IO_ERROR; } } - if ((ret > 0) && (FD_ISSET(socket, &fdwrite))) { + if ((ret > 0) && (FD_ISSET(sckt, &fdwrite))) { return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred } } SetLastTranError(env, "timeout occurred", 0); return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred - */ -} // SelectSend +} // SelectRead /** * This function sends data on a connected socket */ static jdwpTransportError -SendData(jdwpTransportEnv* env, j9socket_t sckt, const char* data, int dataLength, jlong deadline = 0) +SendData(jdwpTransportEnv* env, SOCKET sckt, const char* data, int dataLength, jlong deadline = 0) { long left = dataLength; long off = 0; int ret; - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - - // Check if block - while (left > 0){ - jdwpTransportError err = SelectSend(env, sckt, deadline); - if (err != JDWPTRANSPORT_ERROR_NONE) { - return err; - } - - ret = j9sock_write (sckt, (U_8 *)data+off, left, J9SOCK_NOFLAGS); - if (ret < 0){ - SetLastTranError(env, "socket error", ret); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - left -= ret; - off += ret; - } - return JDWPTRANSPORT_ERROR_NONE; - - /* while (left > 0) { jdwpTransportError err = SelectSend(env, sckt, deadline); if (err != JDWPTRANSPORT_ERROR_NONE) { @@ -391,7 +145,7 @@ } ret = send(sckt, (data + off), left, 0); if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(env); + int err = GetLastErrorStatus(); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "socket error", err); @@ -401,18 +155,15 @@ left -= ret; off += ret; } //while - return JDWPTRANSPORT_ERROR_NONE;*/ + return JDWPTRANSPORT_ERROR_NONE; } //SendData /** * This function receives data from a connected socket */ static jdwpTransportError -ReceiveData(jdwpTransportEnv* env, j9socket_t sckt, U_8 * buffer, int dataLength, jlong deadline = 0, int* readByte = 0) +ReceiveData(jdwpTransportEnv* env, SOCKET sckt, char* buffer, int dataLength, jlong deadline = 0, int* readByte = 0) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - long left = dataLength; long off = 0; int ret; @@ -426,34 +177,9 @@ if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - - ret = j9sock_read(sckt, (U_8 *) (buffer + off), left, J9SOCK_NOFLAGS); - - if (ret < 0) { - SetLastTranError(env, "data receiving failed", ret); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - if (ret == 0) { - SetLastTranError(env, "premature EOF", J9SOCK_NOFLAGS); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - left -= ret; - off += ret; - if (readByte != 0) { - *readByte = off; - } - } //while - return JDWPTRANSPORT_ERROR_NONE; - -/* - while (left > 0) { - jdwpTransportError err = SelectRead(env, sckt, deadline); - if (err != JDWPTRANSPORT_ERROR_NONE) { - return err; - } ret = recv(sckt, (buffer + off), left, 0); if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(env); + int err = GetLastErrorStatus(); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "data receiving failed", err); @@ -470,35 +196,52 @@ *readByte = off; } } //while - return JDWPTRANSPORT_ERROR_NONE;*/ + return JDWPTRANSPORT_ERROR_NONE; } // ReceiveData /** + * This function enable/disables socket blocking mode + */ +static bool +SetSocketBlockingMode(jdwpTransportEnv* env, SOCKET sckt, bool isBlocked) +{ + unsigned long ul = isBlocked ? 0 : 1; + if (ioctlsocket(sckt, FIONBIO, &ul) == SOCKET_ERROR) { + SetLastTranError(env, "socket error", GetLastErrorStatus()); + return false; + } + return true; +} // SetSocketBlockingMode() + +/** * This function performes handshake procedure */ static jdwpTransportError -CheckHandshaking(jdwpTransportEnv* env, j9socket_t sckt, jlong handshakeTimeout) +CheckHandshaking(jdwpTransportEnv* env, SOCKET sckt, jlong handshakeTimeout) { const char* handshakeString = "JDWP-Handshake"; - U_8 receivedString[14]; //length of "JDWP-Handshake" + char receivedString[14]; //length of "JDWP-Handshake" + + jlong deadline = (handshakeTimeout == 0) ? 0 : (jlong)GetTickCount() + handshakeTimeout; jdwpTransportError err; - err = SendData(env, sckt, handshakeString, (int)strlen(handshakeString), handshakeTimeout); + err = SendData(env, sckt, handshakeString, (int)strlen(handshakeString), deadline); if (err != JDWPTRANSPORT_ERROR_NONE) { SetLastTranErrorMessagePrefix(env, "'JDWP-Handshake' sending error: "); return err; } - - err = ReceiveData(env, sckt, receivedString, (int)strlen(handshakeString), handshakeTimeout); - + + err = ReceiveData(env, sckt, receivedString, (int)strlen(handshakeString), deadline); if (err != JDWPTRANSPORT_ERROR_NONE) { SetLastTranErrorMessagePrefix(env, "'JDWP-Handshake' receiving error: "); return err; } + if (memcmp(receivedString, handshakeString, 14) != 0) { SetLastTranError(env, "handshake error, 'JDWP-Handshake' is not received", 0); return JDWPTRANSPORT_ERROR_IO_ERROR; } + return JDWPTRANSPORT_ERROR_NONE; }// CheckHandshaking @@ -506,53 +249,42 @@ * This function decodes address and populates sockaddr_in structure */ static jdwpTransportError -DecodeAddress(jdwpTransportEnv* env, const char *address, j9sockaddr_t sa, bool isServer) +DecodeAddress(jdwpTransportEnv* env, const char *address, struct sockaddr_in *sa, bool isServer) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - char * localhost = "127.0.0.1"; - char * anyhost = "0.0.0.0"; -// memset(sa, 0, sizeof(struct sockaddr_in)); -// sa->sin_family = AF_INET; + memset(sa, 0, sizeof(struct sockaddr_in)); + sa->sin_family = AF_INET; if ((address == 0) || (*address == 0)) { //empty address - j9sock_sockaddr(sa, isServer ? anyhost : localhost, 0); -// sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); -// sa->sin_port = 0; + sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); + sa->sin_port = 0; return JDWPTRANSPORT_ERROR_NONE; } const char* colon = strchr(address, ':'); if (colon == 0) { //address is like "port" - j9sock_sockaddr(sa, isServer ? anyhost : localhost, j9sock_htons((U_16)atoi(address))); - //sa->sin_port = htons((u_short)atoi(address)); - //sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); + sa->sin_port = htons((u_short)atoi(address)); + sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); } else { //address is like "host:port" - //sa->sin_port = htons((u_short)atoi(colon + 1)); + sa->sin_port = htons((u_short)atoi(colon + 1)); + char *hostName = (char*)(((internalEnv*)env->functions->reserved1) ->alloc)((jint)(colon - address + 1)); if (hostName == 0) { SetLastTranError(env, "out of memory", 0); return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } - memcpy(hostName, address, colon - address); + memcpy(hostName, address, colon - address); hostName[colon - address] = '\0'; - int ret = j9sock_sockaddr(sa, hostName, j9sock_htons((U_16)atoi(colon + 1))); - if (ret != 0){ - SetLastTranError(env, "unable to resolve host name", 0); - (((internalEnv*)env->functions->reserved1)->free)(hostName); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - /* sa->sin_addr.s_addr = inet_addr(hostName); - if (ret != 0) { + sa->sin_addr.s_addr = inet_addr(hostName); + if (sa->sin_addr.s_addr == INADDR_NONE) { struct hostent *host = gethostbyname(hostName); if (host == 0) { SetLastTranError(env, "unable to resolve host name", 0); (((internalEnv*)env->functions->reserved1)->free)(hostName); return JDWPTRANSPORT_ERROR_IO_ERROR; } - //TODO delete this memcpy(&(sa->sin_addr), host->h_addr_list[0], host->h_length); - } //if*/ + memcpy(&(sa->sin_addr), host->h_addr_list[0], host->h_length); + } //if (((internalEnv*)env->functions->reserved1)->free)(hostName); } //if return JDWPTRANSPORT_ERROR_NONE; @@ -567,8 +299,9 @@ { memset(capabilitiesPtr, 0, sizeof(JDWPTransportCapabilities)); capabilitiesPtr->can_timeout_attach = 1; - capabilitiesPtr->can_timeout_accept = 1; + capabilitiesPtr->can_timeout_accept = 1; capabilitiesPtr->can_timeout_handshake = 1; + return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_GetCapabilities @@ -577,89 +310,46 @@ */ static jdwpTransportError JNICALL TCPIPSocketTran_Close(jdwpTransportEnv* env) -{ - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == NULL) { +{ + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == INVALID_SOCKET) { return JDWPTRANSPORT_ERROR_NONE; } - ((internalEnv*)env->functions->reserved1)->envClientSocket = NULL; - if (j9sock_socketIsValid(envClientSocket)==0){ - return JDWPTRANSPORT_ERROR_NONE; - } + ((internalEnv*)env->functions->reserved1)->envClientSocket = INVALID_SOCKET; int err; - err = j9sock_shutdown_input(envClientSocket); - if (err == 0){ - err = j9sock_shutdown_output(envClientSocket); - } - if (err != 0) { - SetLastTranError(env, "shutdown socket failed", GetLastErrorStatus(env)); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } -/*#ifdef WIN32 - SOCKET socket = envClientSocket->ipv4; - err = closesocket(socket); -#else - SOCKET socket = envClientSocket->sock; - err = close(socket); -#endif*/ - err = j9sock_close(&envClientSocket); - - if (err != 0) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - return JDWPTRANSPORT_ERROR_NONE; - -/* err = shutdown(envClientSocket, SD_BOTH); + err = shutdown(envClientSocket, SD_BOTH); if (err == SOCKET_ERROR) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); + SetLastTranError(env, "close socket failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } err = closesocket(envClientSocket); if (err == SOCKET_ERROR) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); + SetLastTranError(env, "close socket failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } - return JDWPTRANSPORT_ERROR_NONE;*/ + return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_Close /** * This function sets socket options SO_REUSEADDR and TCP_NODELAY */ static bool -SetSocketOptions(jdwpTransportEnv* env, j9socket_t sckt) +SetSocketOptions(jdwpTransportEnv* env, SOCKET sckt) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - - BOOLEAN isOn = TRUE; - - if (j9sock_setopt_bool(sckt, J9_SOL_SOCKET, J9_SO_REUSEADDR, &isOn) != 0){ - SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus(env)); - return false; - } - if (j9sock_setopt_bool(sckt, J9_IPPROTO_IP, J9_TCP_NODELAY, &isOn) != 0) { - SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus(env)); - return false; - } - - return true; - -/* if (setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { - SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus(env)); + BOOL isOn = TRUE; + if (setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { + SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus()); return false; } if (setsockopt(sckt, IPPROTO_TCP, TCP_NODELAY, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { - SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus(env)); + SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus()); return false; } - return true;*/ + return true; } // SetSocketOptions() /** @@ -669,12 +359,6 @@ TCPIPSocketTran_Attach(jdwpTransportEnv* env, const char* address, jlong attachTimeout, jlong handshakeTimeout) { - internalEnv *ienv = (internalEnv*)env->functions->reserved1; - PORT_ACCESS_FROM_JAVAVM(ienv->jvm); - - j9socket_t clientSocket; - j9sockaddr_struct serverSockAddr; - if ((address == 0) || (*address == 0)) { SetLastTranError(env, "address is missing", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; @@ -690,27 +374,27 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket != NULL) { + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket != INVALID_SOCKET) { SetLastTranError(env, "there is already an open connection to the debugger", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket != NULL) { + SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket != INVALID_SOCKET) { SetLastTranError(env, "transport is currently in listen mode", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } + struct sockaddr_in serverSockAddr; jdwpTransportError res = DecodeAddress(env, address, &serverSockAddr, false); if (res != JDWPTRANSPORT_ERROR_NONE) { return res; } - int ret = j9sock_socket(&clientSocket,J9SOCK_AFINET, J9SOCK_STREAM, J9SOCK_DEFPROTOCOL); - // socket(AF_INET, SOCK_STREAM, 0); - if (ret != 0) { - SetLastTranError(env, "unable to create socket", GetLastErrorStatus(env)); + SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, 0); + if (clientSocket == INVALID_SOCKET) { + SetLastTranError(env, "unable to create socket", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } @@ -722,49 +406,43 @@ if (!SetSocketBlockingMode(env, clientSocket, true)) { return JDWPTRANSPORT_ERROR_IO_ERROR; } - int err = j9sock_connect(clientSocket, &serverSockAddr); - //int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); - if (err != 0 ) { - SetLastTranError(env, "connection failed", GetLastErrorStatus(env)); + int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); + if (err == SOCKET_ERROR) { + SetLastTranError(env, "connection failed", GetLastErrorStatus()); SetSocketBlockingMode(env, clientSocket, false); return JDWPTRANSPORT_ERROR_IO_ERROR; - } + } if (!SetSocketBlockingMode(env, clientSocket, false)) { return JDWPTRANSPORT_ERROR_IO_ERROR; - } + } } else { if (!SetSocketBlockingMode(env, clientSocket, false)) { return JDWPTRANSPORT_ERROR_IO_ERROR; } - int err = j9sock_connect(clientSocket, &serverSockAddr); - if (err != 0) { - if (err != J9PORT_ERROR_SOCKET_WOULDBLOCK) { - SetLastTranError(env, "connection failed", GetLastErrorStatus(env)); + int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); + if (err == SOCKET_ERROR) { + if (GetLastErrorStatus() != SOCKETWOULDBLOCK) { + SetLastTranError(env, "connection failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; - } else { - int ret = SelectSend(env, clientSocket, handshakeTimeout); - if (ret == JDWPTRANSPORT_ERROR_NONE){ - return JDWPTRANSPORT_ERROR_NONE; - } - return JDWPTRANSPORT_ERROR_IO_ERROR; -//TODO delele this selectWrite - /*fd_set fdwrite; + } else { + fd_set fdwrite; FD_ZERO(&fdwrite); FD_SET(clientSocket, &fdwrite); TIMEVAL tv = {(long)(attachTimeout / 1000), (long)(attachTimeout % 1000)}; int ret = select((int)clientSocket + 1, NULL, &fdwrite, NULL, &tv); if (ret == SOCKET_ERROR) { - SetLastTranError(env, "socket error", GetLastErrorStatus(env)); + SetLastTranError(env, "socket error", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } if ((ret != 1) || !(FD_ISSET(clientSocket, &fdwrite))) { SetLastTranError(env, "timeout occurred", 0); return JDWPTRANSPORT_ERROR_IO_ERROR; - }*/ + } } } } + EnterCriticalSendSection(env); EnterCriticalReadSection(env); ((internalEnv*)env->functions->reserved1)->envClientSocket = clientSocket; @@ -775,6 +453,7 @@ TCPIPSocketTran_Close(env); return res; } + return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_Attach @@ -785,32 +464,28 @@ TCPIPSocketTran_StartListening(jdwpTransportEnv* env, const char* address, char** actualAddress) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket != NULL) { + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket != INVALID_SOCKET) { SetLastTranError(env, "there is already an open connection to the debugger", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket != NULL) { + SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket != INVALID_SOCKET) { SetLastTranError(env, "transport is currently in listen mode", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } jdwpTransportError res; - j9sockaddr_struct serverSockAddr; + struct sockaddr_in serverSockAddr; res = DecodeAddress(env, address, &serverSockAddr, true); if (res != JDWPTRANSPORT_ERROR_NONE) { return res; } - j9socket_t serverSocket; - int ret = j9sock_socket(&serverSocket,J9SOCK_AFINET, J9SOCK_STREAM, J9SOCK_DEFPROTOCOL); //socket(AF_INET, SOCK_STREAM, 0); - if (ret != 0) { - SetLastTranError(env, "unable to create socket", GetLastErrorStatus(env)); + SOCKET serverSocket = socket(AF_INET, SOCK_STREAM, 0); + if (serverSocket == INVALID_SOCKET) { + SetLastTranError(env, "unable to create socket", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } @@ -820,16 +495,15 @@ int err; - err = j9sock_bind (serverSocket, &serverSockAddr); - // bind(serverSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); - if (err != 0 ) { - SetLastTranError(env, "binding to port failed", GetLastErrorStatus(env)); + err = bind(serverSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); + if (err == SOCKET_ERROR) { + SetLastTranError(env, "binding to port failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - err = j9sock_listen(serverSocket, J9SOCK_MAXCONN); - if (err != 0) { - SetLastTranError(env, "listen start failed", GetLastErrorStatus(env)); + err = listen(serverSocket, SOMAXCONN); + if (err == SOCKET_ERROR) { + SetLastTranError(env, "listen start failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } @@ -839,9 +513,10 @@ ((internalEnv*)env->functions->reserved1)->envServerSocket = serverSocket; - err = j9sock_getsockname(serverSocket, &serverSockAddr); - if (err != 0) { - SetLastTranError(env, "socket error", GetLastErrorStatus(env)); + socklen_t len = sizeof(serverSockAddr); + err = getsockname(serverSocket, (struct sockaddr *)&serverSockAddr, &len); + if (err == SOCKET_ERROR) { + SetLastTranError(env, "socket error", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } @@ -872,8 +547,7 @@ SetLastTranError(env, "out of memory", 0); return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } - // print server port - sprintf(retAddress, "%d",j9sock_sockaddr_port(&serverSockAddr)); + sprintf(retAddress, "%d", ntohs(serverSockAddr.sin_port)); *actualAddress = retAddress; @@ -886,27 +560,17 @@ static jdwpTransportError JNICALL TCPIPSocketTran_StopListening(jdwpTransportEnv* env) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - - j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket == NULL) { + SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket == INVALID_SOCKET) { return JDWPTRANSPORT_ERROR_NONE; } -/*#ifdef WIN32 - SOCKET socket = envServerSocket->ipv4; - int err = closesocket(socket); -#else - SOCKET socket = envServerSocket->sock; - int err = close(socket); -#endif */ - int err = j9sock_close(&envServerSocket); - if (err != 0) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); + + if (closesocket(envServerSocket) == SOCKET_ERROR) { + SetLastTranError(env, "close socket failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } - ((internalEnv*)env->functions->reserved1)->envServerSocket = NULL; + ((internalEnv*)env->functions->reserved1)->envServerSocket = INVALID_SOCKET; return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_StopListening @@ -918,9 +582,6 @@ TCPIPSocketTran_Accept(jdwpTransportEnv* env, jlong acceptTimeout, jlong handshakeTimeout) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - if (acceptTimeout < 0) { SetLastTranError(env, "acceptTimeout timeout is negative", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; @@ -931,43 +592,35 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket != NULL) { + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket != INVALID_SOCKET) { SetLastTranError(env, "there is already an open connection to the debugger", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket == NULL) { + SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket == INVALID_SOCKET) { SetLastTranError(env, "transport is not currently in listen mode", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - j9sockaddr_struct serverSockAddr; -/* int res = j9sock_getpeername(envServerSocket, &serverSockAddr); + struct sockaddr serverSockAddr; + socklen_t len = sizeof(serverSockAddr); + int res = getsockname(envServerSocket, &serverSockAddr, &len); if (res == SOCKET_ERROR) { - SetLastTranError(env, "connection failed", GetLastErrorStatus(env)); + SetLastTranError(env, "connection failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; - }*/ - - //jlong deadline = (acceptTimeout == 0) ? 0 : (jlong)GetTickCount() + acceptTimeout; - I_32 ret = SelectRead(env, envServerSocket, acceptTimeout); - //I_32 ret = j9sock_select_read(envServerSocket, (I_32)acceptTimeout/1000, (I_32)acceptTimeout%1000, TRUE); - - if (ret != JDWPTRANSPORT_ERROR_NONE){ - if (ret != J9PORT_ERROR_SOCKET_TIMEOUT){ - SetLastTranError(env, "socket error", ret); - return JDWPTRANSPORT_ERROR_IO_ERROR; - } - SetLastTranError(env, "timeout occurred", 0); - return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred } - j9socket_t clientSocket; - ret = j9sock_accept(envServerSocket, &serverSockAddr, &clientSocket); + jlong deadline = (acceptTimeout == 0) ? 0 : (jlong)GetTickCount() + acceptTimeout; + jdwpTransportError err = SelectRead(env, envServerSocket, deadline); + if (err != JDWPTRANSPORT_ERROR_NONE) { + return err; + } - if (ret != 0) { - SetLastTranError(env, "socket accept failed", GetLastErrorStatus(env)); + SOCKET clientSocket = accept(envServerSocket, &serverSockAddr, &len); + if (clientSocket == INVALID_SOCKET) { + SetLastTranError(env, "socket accept failed", GetLastErrorStatus()); return JDWPTRANSPORT_ERROR_IO_ERROR; } @@ -978,13 +631,15 @@ EnterCriticalSendSection(env); EnterCriticalReadSection(env); ((internalEnv*)env->functions->reserved1)->envClientSocket = clientSocket; - jdwpTransportError err = CheckHandshaking(env, clientSocket, (long)handshakeTimeout); + + err = CheckHandshaking(env, clientSocket, (long)handshakeTimeout); LeaveCriticalReadSection(env); LeaveCriticalSendSection(env); if (err != JDWPTRANSPORT_ERROR_NONE) { TCPIPSocketTran_Close(env); return err; } + return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_Accept @@ -994,8 +649,8 @@ static jboolean JNICALL TCPIPSocketTran_IsOpen(jdwpTransportEnv* env) { - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == NULL) { + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == INVALID_SOCKET) { return JNI_FALSE; } return JNI_TRUE; @@ -1005,15 +660,12 @@ * This function read packet */ static jdwpTransportError -ReadPacket(jdwpTransportEnv* env, j9socket_t envClientSocket, jdwpPacket* packet) +ReadPacket(jdwpTransportEnv* env, SOCKET envClientSocket, jdwpPacket* packet) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); - jdwpTransportError err; int length; int readBytes = 0; - err = ReceiveData(env, envClientSocket, (U_8 *)&length, sizeof(jint), 0, &readBytes); + err = ReceiveData(env, envClientSocket, (char *)&length, sizeof(jint), 0, &readBytes); if (err != JDWPTRANSPORT_ERROR_NONE) { if (readBytes == 0) { packet->type.cmd.len = 0; @@ -1021,35 +673,36 @@ } return err; } - packet->type.cmd.len = (jint)j9sock_ntohl(length); + + packet->type.cmd.len = (jint)ntohl(length); int id; - err = ReceiveData(env, envClientSocket, (U_8 *)&(id), sizeof(jint)); + err = ReceiveData(env, envClientSocket, (char *)&(id), sizeof(jint)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - packet->type.cmd.id = (jint)j9sock_ntohl(id); + packet->type.cmd.id = (jint)ntohl(id); - err = ReceiveData(env, envClientSocket, (U_8 *)&(packet->type.cmd.flags), sizeof(jbyte)); + err = ReceiveData(env, envClientSocket, (char *)&(packet->type.cmd.flags), sizeof(jbyte)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { - int errorCode; - err = ReceiveData(env, envClientSocket, (U_8*)&(errorCode), sizeof(jshort)); + u_short errorCode; + err = ReceiveData(env, envClientSocket, (char*)&(errorCode), sizeof(jshort)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - packet->type.reply.errorCode = (jshort)j9sock_ntohs(errorCode); + packet->type.reply.errorCode = (jshort)ntohs(errorCode); } else { - err = ReceiveData(env, envClientSocket, (U_8*)&(packet->type.cmd.cmdSet), sizeof(jbyte)); + err = ReceiveData(env, envClientSocket, (char*)&(packet->type.cmd.cmdSet), sizeof(jbyte)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - err = ReceiveData(env, envClientSocket, (U_8*)&(packet->type.cmd.cmd), sizeof(jbyte)); + err = ReceiveData(env, envClientSocket, (char*)&(packet->type.cmd.cmd), sizeof(jbyte)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } @@ -1067,7 +720,7 @@ SetLastTranError(env, "out of memory", 0); return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } - err = ReceiveData(env, envClientSocket, (U_8 *)packet->type.cmd.data, dataLength); + err = ReceiveData(env, envClientSocket, (char *)packet->type.cmd.data, dataLength); if (err != JDWPTRANSPORT_ERROR_NONE) { (((internalEnv*)env->functions->reserved1)->free)(packet->type.cmd.data); return err; @@ -1087,8 +740,8 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == NULL) { + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == INVALID_SOCKET) { SetLastTranError(env, "there isn't an open connection to a debugger", 0); LeaveCriticalReadSection(env); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; @@ -1104,10 +757,8 @@ * This function implements jdwpTransportEnv::WritePacket */ static jdwpTransportError -WritePacket(jdwpTransportEnv* env, j9socket_t envClientSocket, const jdwpPacket* packet) +WritePacket(jdwpTransportEnv* env, SOCKET envClientSocket, const jdwpPacket* packet) { - JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; - PORT_ACCESS_FROM_JAVAVM(vm); int packetLength = packet->type.cmd.len; if (packetLength < 11) { SetLastTranError(env, "invalid packet length", 0); @@ -1121,7 +772,7 @@ } int dataLength = packetLength - 11; - packetLength = j9sock_htonl(packetLength); + packetLength = htonl(packetLength); jdwpTransportError err; err = SendData(env, envClientSocket, (char*)&packetLength, sizeof(jint)); @@ -1129,7 +780,7 @@ return err; } - int id = j9sock_htonl (packet->type.cmd.id); + int id = htonl(packet->type.cmd.id); err = SendData(env, envClientSocket, (char*)&id, sizeof(jint)); if (err != JDWPTRANSPORT_ERROR_NONE) { @@ -1142,7 +793,7 @@ } if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { - int errorCode = htons(packet->type.reply.errorCode); + u_short errorCode = htons(packet->type.reply.errorCode); err = SendData(env, envClientSocket, (char*)&errorCode, sizeof(jshort)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; @@ -1179,10 +830,10 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == NULL) { + SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == INVALID_SOCKET) { SetLastTranError(env, "there isn't an open connection to a debugger", 0); - //LeaveCriticalSendSection(env); + LeaveCriticalSendSection(env); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE; } @@ -1199,7 +850,6 @@ TCPIPSocketTran_GetLastError(jdwpTransportEnv* env, char** message) { *message = ((internalEnv*)env->functions->reserved1)->lastError->GetLastErrorMessage(); - if (*message == 0) { return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE; } @@ -1225,8 +875,8 @@ iEnv->alloc = callback->alloc; iEnv->free = callback->free; iEnv->lastError = 0; - iEnv->envClientSocket = NULL; - iEnv->envServerSocket = NULL; + iEnv->envClientSocket = INVALID_SOCKET; + iEnv->envServerSocket = INVALID_SOCKET; jdwpTransportNativeInterface_* envTNI = (jdwpTransportNativeInterface_*)callback ->alloc(sizeof(jdwpTransportNativeInterface_)); @@ -1281,4 +931,4 @@ unLoadFree((void*)(*env)->functions); unLoadFree((void*)(*env)); } //jdwpTransport_UnLoad -#endif + Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h Wed May 7 05:33:27 2008 @@ -33,13 +33,6 @@ #ifndef _SOCKETTRANSPORT_H #define _SOCKETTRANSPORT_H -#include "SocketTransport_pd.h" -#include "j9thread.h" -//#include "jni.h" - -typedef j9thread_monitor_t CriticalSection; -//typedef jobject CriticalSection; - struct internalEnv { JavaVM *jvm; // the JNI invocation interface, provided // by the agent @@ -47,8 +40,8 @@ // provided by the agent void (*free)(void *buffer); // the function deallocating an area of memory, // provided by the agent - j9socket_t envClientSocket; // the client socket, INVALID_SOCKET if closed - j9socket_t envServerSocket; // the server socket, INVALID_SOCKET if closed + SOCKET envClientSocket; // the client socket, INVALID_SOCKET if closed + SOCKET envServerSocket; // the server socket, INVALID_SOCKET if closed LastTransportError* lastError; // last errors CriticalSection readLock; // the critical-section lock object for socket // read operations Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp Wed May 7 05:33:27 2008 @@ -134,7 +134,7 @@ JDWP_TRACE_PROG("StartDebugger: launched: pid=" << pid); } } -/* + ProcPtr jdwp::GetProcAddress(LoadedLibraryHandler libHandler, const char* procName) { JDWP_TRACE_ENTRY("GetProcAddress(" << libHandler << ',' << JDWP_CHECK_NULL(procName) << ')'); @@ -148,7 +148,6 @@ return res; } - bool jdwp::FreeLibrary(LoadedLibraryHandler libHandler) { JDWP_TRACE_ENTRY("FreeLibrary(" << libHandler << ')'); @@ -185,4 +184,4 @@ JDWP_TRACE_PROG("LoadTransport: transport library " << transportFullName << " loaded"); } return res; -}*/ +} Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile Wed May 7 05:33:27 2008 @@ -28,6 +28,8 @@ INCLUDES += -I$(CMNAGENT)commands -I$(CMNAGENT)core \ -I$(COMMON)generic -Icore +INCLUDES := -I../../../include $(INCLUDES) + LDFLAGS += -lstdc++ BUILDFILES = \ @@ -51,9 +53,10 @@ $(CMNAGENT)core/ObjectManager.o $(CMNAGENT)core/OptionParser.o $(CMNAGENT)core/PacketDispatcher.o \ $(CMNAGENT)core/PacketParser.o $(CMNAGENT)core/RequestManager.o $(CMNAGENT)core/RequestModifier.o \ $(CMNAGENT)core/ThreadManager.o $(CMNAGENT)core/TransportManager.o $(CMNAGENT)core/AgentManager.o \ + $(CMNAGENT)core/CallBacks.o \ core/TransportManager_pd.o -MDLLIBFILES = $(LIBPATH)libj9vmi.a +MDLLIBFILES = DLLNAME = ../libjdwp.so Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h Wed May 7 05:33:27 2008 @@ -33,19 +33,24 @@ #define _SOCKETTRANSPORT_PD_H -#include "LastTransportError.h" -#include "vmi.h" -#include "j9thread.h" -#include "j9socket.h" -#include "portsock.h" -#include "j9port.h" - -//#include "j9sock.h" -#include "jni.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -//typedef pthread_mutex_t CriticalSection; +typedef pthread_mutex_t CriticalSection; typedef int SOCKET; -//typedef pthread_t ThreadId_t; +typedef pthread_t ThreadId_t; #include "jdwpTransport.h" #include "LastTransportError.h" @@ -54,8 +59,118 @@ typedef timeval TIMEVAL; typedef int BOOL; -const int SOCKETWOULDBLOCK = J9PORT_ERROR_SOCKET_WOULDBLOCK; -const int SOCKET_ERROR_EINTR = J9PORT_ERROR_SOCKET_INTERRUPTED; +const int TRUE = 1; const int SOCKET_ERROR = -1; +const int SOCKET_ERROR_EINTR = EINTR; +const int INVALID_SOCKET = -1; +const int SD_BOTH = 2; +const int SOCKETWOULDBLOCK = EINPROGRESS; + +/** + * Returns the error status for the last failed operation. + */ +static inline int +GetLastErrorStatus() +{ + return errno; +} + +/** + * Retrieves the number of milliseconds, substitute for the corresponding Win32 + * function. + */ +static inline long +GetTickCount(void) +{ + struct timeval t; + gettimeofday(&t, 0); + return t.tv_sec * 1000 + (t.tv_usec/1000); +} + +/** + * Closes socket, substitute for the corresponding Win32 function. + */ +static inline int +closesocket(SOCKET s) +{ + return close(s); +} + +/** + * Closes socket, substitute for the corresponding Win32 function. + */ +static inline int +ioctlsocket( SOCKET s, long cmd, u_long* argp) +{ + return ioctl(s, cmd, argp); +} + +/** + * Initializes critical-section lock objects. + */ +static inline void +InitializeCriticalSections(jdwpTransportEnv* env) +{ + pthread_mutex_init(&(((internalEnv*)env->functions->reserved1)->readLock), 0); + pthread_mutex_init(&(((internalEnv*)env->functions->reserved1)->sendLock), 0); +} + +/** + * Releases all resources used by critical-section lock objects. + */ +static inline void +DeleteCriticalSections(jdwpTransportEnv* env) +{ + pthread_mutex_destroy(&(((internalEnv*)env->functions->reserved1)->readLock)); + pthread_mutex_destroy(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} + +/** + * Waits for ownership of the read critical-section object. + */ +static inline void +EnterCriticalReadSection(jdwpTransportEnv* env) +{ + pthread_mutex_lock(&(((internalEnv*)env->functions->reserved1)->readLock)); +} + +/** + * Waits for ownership of the send critical-section object. + */ +static inline void +EnterCriticalSendSection(jdwpTransportEnv* env) +{ + pthread_mutex_lock(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} + +/** + * Releases ownership of the read critical-section object. + */ +static inline void +LeaveCriticalReadSection(jdwpTransportEnv* env) +{ + pthread_mutex_unlock(&(((internalEnv*)env->functions->reserved1)->readLock)); +} + +/** + * Releases ownership of the send critical-section object. + */ +static inline void +LeaveCriticalSendSection(jdwpTransportEnv* env) +{ + pthread_mutex_unlock(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} + +static inline ThreadId_t +GetCurrentThreadId() +{ + return pthread_self(); +} // GetCurrentThreadId() + +static inline bool +ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2) +{ + return pthread_equal(treadId1, treadId2) != 0 ? true : false; +} // ThreadId_equal() #endif //_SOCKETTRANSPORT_PD_H Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile Wed May 7 05:33:27 2008 @@ -30,7 +30,7 @@ CXXFLAGS += -fpic INCLUDES += -I$(CMNTRANS)common -I$(CMNTRANS)dt_socket \ - -I$(COMMON)generic -Idt_socket -I$(HY_HDK)/include/port/unix_include + -I$(COMMON)generic -Idt_socket LDFLAGS += -lstdc++ @@ -38,7 +38,7 @@ $(CMNTRANS)common/LastTransportError.o \ $(CMNTRANS)dt_socket/SocketTransport.o -MDLLIBFILES = $(LIBPATH)libj9vmi.a $(LIBPATH)libj9prt24.so +MDLLIBFILES = DLLNAME = ../libdt_socket.so Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp Wed May 7 05:33:27 2008 @@ -99,4 +99,27 @@ CloseHandle(pi.hThread); } +LoadedLibraryHandler TransportManager::LoadTransport(const char* dirName, const char* transportName) +{ + JDWP_TRACE_ENTRY("LoadTransport(" << JDWP_CHECK_NULL(dirName) << ',' << JDWP_CHECK_NULL(transportName) << ')'); + JDWP_ASSERT(transportName != 0); + char* transportFullName = 0; + if (dirName == 0) { + size_t length = strlen(transportName) + 5; + transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); + sprintf(transportFullName, "%s.dll", transportName); + } else { + size_t length = strlen(dirName) + strlen(transportName) + 6; + transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); + sprintf(transportFullName, "%s\\%s.dll", dirName, transportName); + } + AgentAutoFree afv(transportFullName JDWP_FILE_LINE); + LoadedLibraryHandler res = LoadLibrary(transportFullName); + if (res == 0) { + JDWP_TRACE_PROG("LoadTransport: loading library " << transportFullName << " failed (error code: " << GetLastError() << ")"); + } else { + JDWP_TRACE_PROG("LoadTransport: transport library " << transportFullName << " loaded"); + } + return res; +} Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile Wed May 7 05:33:27 2008 @@ -30,7 +30,7 @@ -I$(CMNAGENT)commands -I$(CMNAGENT)core \ -I$(COMMON)generic -Icore -HYCFLAGS = $(HYCFLAGS) $(INCLUDES) -GX -wd4290 +HYCFLAGS = -I..\..\..\include $(HYCFLAGS) $(INCLUDES) -GX -wd4290 HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def @@ -62,7 +62,7 @@ SYSLIBFILES = -MDLLIBFILES =$(LIBPATH)vmi.lib $(LIBPATH)j9thr.lib $(LIBPATH)j9prt.lib +MDLLIBFILES = DLLBASE=0x13200000 COMMENT=/comment:"JDWP agent native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable." Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h Wed May 7 05:33:27 2008 @@ -35,18 +35,16 @@ #if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_) #undef _WINSOCKAPI_ #endif -#ifndef HY_NO_THR -#define HY_NO_THR #include #include +typedef CRITICAL_SECTION CriticalSection; +typedef DWORD ThreadId_t; + #include "jdwpTransport.h" -#include "vmi.h" -#include "j9port.h" #include "LastTransportError.h" #include "SocketTransport.h" -#include "jni.h" typedef int socklen_t; @@ -61,5 +59,66 @@ { return WSAGetLastError(); } //GetLastErrorStatus() -#endif // HY_NO_THR -#endif // _SOCKETTRANSPORT_PD_Hi + +/** + * Initializes critical section lock objects. + */ +static inline void +InitializeCriticalSections(jdwpTransportEnv* env) +{ + InitializeCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); + InitializeCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} //InitializeCriticalSections() + +/** + * Releases all resources used by critical-section lock objects. + */ +static inline void +DeleteCriticalSections(jdwpTransportEnv* env) +{ + DeleteCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); + DeleteCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} //DeleteCriticalSections() + +/** + * Waits for ownership of the read critical-section object. + */ +static inline void +EnterCriticalReadSection(jdwpTransportEnv* env) +{ + EnterCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); +} //EnterCriticalReadSection() + +/** + * Waits for ownership of the send critical-section object. + */ +static inline void +EnterCriticalSendSection(jdwpTransportEnv* env) +{ + EnterCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} //EnterCriticalSendSection() + +/** + * Releases ownership of the read critical-section object. + */ +static inline void +LeaveCriticalReadSection(jdwpTransportEnv* env) +{ + LeaveCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); +} //LeaveCriticalReadSection() + +/** + * Releases ownership of the send critical-section object. + */ +static inline void +LeaveCriticalSendSection(jdwpTransportEnv* env) +{ + LeaveCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); +} //LeaveCriticalSendSection() + +static inline bool ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2) +{ + return (treadId1 == treadId2); +} // ThreadId_equal() + +#endif // _SOCKETTRANSPORT_PD_H Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile?rev=654082&r1=654081&r2=654082&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile Wed May 7 05:33:27 2008 @@ -27,7 +27,6 @@ LIBNAME=$(LIBPATH)$(LIBBASE).lib INCLUDES = $(INCLUDES) \ - -I$(HY_HDK)\include\port\win32_include \ -I$(CMNTRANS)common -I$(CMNTRANS)dt_socket \ -I$(COMMON)generic -Idt_socket @@ -44,7 +43,7 @@ SYSLIBFILES = -MDLLIBFILES =$(LIBPATH)vmi.lib $(LIBPATH)j9thr.lib $(LIBPATH)j9prt.lib +MDLLIBFILES = DLLBASE=0x13200000 COMMENT=/comment:"JDWP socket transport native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."