You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2007/10/12 19:18:55 UTC

svn commit: r584204 - in /harmony/enhanced/drlvm/trunk/vm: port/include/port_vmem.h port/src/vmem/linux/port_vmem.c port/src/vmem/win/port_vmem.c vmcore/src/thread/thread_generic.cpp

Author: gshimansky
Date: Fri Oct 12 10:18:53 2007
New Revision: 584204

URL: http://svn.apache.org/viewvc?rev=584204&view=rev
Log:
Added functions for allocation of memory with specified permission modes.
JVMTI breakpoint handling buffer is now allocated using these function
with execution mode enabled for it.


Modified:
    harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h
    harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c
    harmony/enhanced/drlvm/trunk/vm/port/src/vmem/win/port_vmem.c
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h?rev=584204&r1=584203&r2=584204&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h Fri Oct 12 10:18:53 2007
@@ -159,6 +159,27 @@
  */
 APR_DECLARE(size_t) port_vmem_max_size();
 
+/**
+ * Allocate memory with default page size.
+ * @param[in,out] addr - desired starting address of the region to allocate. If
+ *                       <code>NULL</code>, the system determines the
+ *                       appropriate location.On success, the actual
+ *                       allocated address is returned
+ * @param size         - the size of the region in bytes. For large pages,
+                         the size must be multiply of page size
+ * @param mode  - the bit mask of <code>PORT_VMEM_MODE_*</code> flags
+ */
+APR_DECLARE(apr_status_t) port_vmem_allocate(void **addr, size_t size, unsigned int mode);
+
+/**
+ * Releases previously reserved virtual memory region as a whole.
+ * If the region was committed, the function first decommits it.
+ * @param addr - the memory region address
+ * @param size - size of the allocated memory
+ * @return <code>APR_SUCCESS</code> if OK; otherwise, an error code.
+ */
+APR_DECLARE(apr_status_t) port_vmem_free(void *addr, size_t size);
+
 /** @} */
 
 #ifdef __cplusplus

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c?rev=584204&r1=584203&r2=584204&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c Fri Oct 12 10:18:53 2007
@@ -203,6 +203,34 @@
     return rlim;
 }
 
+APR_DECLARE(apr_status_t) port_vmem_allocate(void **addr, size_t size, unsigned int mode)
+{
+    void *start = NULL;
+    int protection = convertProtectionBits(mode);
+
+#ifdef MAP_ANONYMOUS
+    start = mmap(*addr, size, protection, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+#elif defined(MAP_ANON)
+    start = mmap(*addr, size, protection, MAP_PRIVATE | MAP_ANON, -1, 0);
+#else
+    int fd = open("/dev/zero", O_RDONLY);
+    start = mmap(*addr, size, protection, MAP_PRIVATE, fd, 0);
+    close(fd);
+#endif
+
+    if (MAP_FAILED == start)
+        return apr_get_os_error();
+
+    *addr = start;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) port_vmem_free(void *addr, size_t size)
+{
+	munmap(addr, size);
+	return APR_SUCCESS;
+}
+
 #ifdef __cplusplus
 }
 #endif

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/vmem/win/port_vmem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/vmem/win/port_vmem.c?rev=584204&r1=584203&r2=584204&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/vmem/win/port_vmem.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/vmem/win/port_vmem.c Fri Oct 12 10:18:53 2007
@@ -244,6 +244,29 @@
     }
 }
 
+APR_DECLARE(apr_status_t) port_vmem_allocate(void **addr, size_t size, unsigned int mode)
+{
+    LPVOID start = NULL;
+    DWORD protection = convertProtectionMask(mode);
+
+	start = VirtualAlloc(*addr, size, MEM_COMMIT, protection);
+	if (!start) {
+		return apr_get_os_error();
+	}
+
+    *addr = start;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) port_vmem_free(void *addr, size_t UNREF size)
+{
+	if (!VirtualFree(addr, 0, MEM_RELEASE)) {
+		return apr_get_os_error();
+	}
+
+	return APR_SUCCESS;
+}
+
 #ifdef __cplusplus
 }
 #endif

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp?rev=584204&r1=584203&r2=584204&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp Fri Oct 12 10:18:53 2007
@@ -221,9 +221,13 @@
         vm_thread->jvmti_thread.owned_monitors = (jobject*)apr_palloc(vm_thread->pool,
                 TM_INITIAL_OWNED_MONITOR_SIZE * sizeof(jobject));
 
+        void *addr = NULL;
+        apr_status_t UNREF status = port_vmem_allocate(&addr, TM_JVMTI_MAX_BUFFER_SIZE,
+            PORT_VMEM_MODE_READ | PORT_VMEM_MODE_WRITE | PORT_VMEM_MODE_EXECUTE);
+        assert(status == APR_SUCCESS);
+
         vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer =
-            (jbyte*)apr_palloc(vm_thread->pool,
-                sizeof(jbyte) * TM_JVMTI_MAX_BUFFER_SIZE);
+            reinterpret_cast<jbyte *>(addr);
     }
     ((hythread_t)vm_thread)->java_status = TM_STATUS_INITIALIZED;
 
@@ -262,6 +266,15 @@
     // Remove guard page on the stack on linux
     remove_guard_stack(p_vm_thread);
 #endif // PLATFORM_POSIX
+
+    if (ti_is_enabled())
+    {
+        apr_status_t UNREF status;
+        status = port_vmem_free(
+            p_vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer,
+            TM_JVMTI_MAX_BUFFER_SIZE);
+        assert(status == APR_SUCCESS);
+    }
 
     // Destroy current VM_thread pool and zero VM_thread structure
     jthread_deallocate_vm_thread_pool(p_vm_thread);