Author: mturk
Date: Thu Jun 18 08:52:57 2009
New Revision: 785962
URL: http://svn.apache.org/viewvc?rev=785962&view=rev
Log:
Add ExecutableMemory allocation implementation
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
(with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java?rev=785962&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
Thu Jun 18 08:52:57 2009
@@ -0,0 +1,49 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ * ExecutableMemory class.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ *
+ * @see OS
+ * @since Runtime 1.0
+ */
+public final class ExecutableMemory {
+
+ private ExecutableMemory()
+ {
+ // No Instance
+ }
+
+
+ /**
+ * Allocates {...@code size} bytes and returns a {...@link Pointer}
+ * to the allocated memory. The memory has executable permissions.
+ *
+ * @param size Size of the memory to allocate.
+ * @return new {...@link Pointer} containing memory area.
+ *
+ * @throws OutOfMemoryError if memory cannot be allocated.
+ * @throws IllegalArgumentException if the size is less then {...@code 1}.
+ */
+ public static native Pointer malloc(long size)
+ throws OutOfMemoryError, IllegalArgumentException;
+
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c?rev=785962&r1=785961&r2=785962&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c Thu Jun 18
08:52:57 2009
@@ -54,7 +54,7 @@
}
ACR_JNI_EXPORT_DECLARE(jobject, ExecutableMemory, malloc)(ACR_JNISTDARGS,
- jlong siz)
+ jlong siz)
{
jobject ptr = NULL;
void *mem;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c?rev=785962&r1=785961&r2=785962&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/execmem.c Thu Jun 18
08:52:57 2009
@@ -38,7 +38,7 @@
}
ACR_JNI_EXPORT_DECLARE(jobject, ExecutableMemory, malloc)(ACR_JNISTDARGS,
- jlong siz)
+ jlong siz)
{
jobject ptr = NULL;
void *mem;
Modified:
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=785962&r1=785961&r2=785962&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
(original)
+++
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
Thu Jun 18 08:52:57 2009
@@ -102,6 +102,14 @@
p.free();
}
+ public void testExecutableMalloc()
+ throws Throwable
+ {
+ Pointer p = ExecutableMemory.malloc(1000);
+ assertNotNull("ExecutablePointer", p);
+ p.free();
+ }
+
public void testSlice()
throws Throwable
{