Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation of native methods #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classlib6.ipr
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@
<option name="mySupportsUserInfoFilter" value="true" />
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="svn" />
<mapping directory="" vcs="Git" />
</component>
<component name="WebServicesPlugin" addRequiredLibraries="true" />
<component name="libraryTable">
Expand Down
4 changes: 3 additions & 1 deletion core/src/classlib/org/jnode/java/io/VMFileSystemAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

package org.jnode.java.io;

import java.io.IOException;
import java.io.File;
import java.io.IOException;
import java.io.VMOpenMode;

/**
Expand Down Expand Up @@ -153,4 +153,6 @@ public boolean setExecutable(String normalizedPath, boolean enable,
public long getFreeSpace(String normalizedPath) throws IOException;

public long getUsableSpace(String normalizedPath) throws IOException;

public int getOpenFileDescriptorCount();
}
4 changes: 4 additions & 0 deletions core/src/classpath/java/java/io/VMIOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public long getUsableSpace(String normalizedPath) throws IOException {
return 0;
}

public int getOpenFileDescriptorCount() {
return 0;
}

public boolean isDirectory(String file) {
return false;
}
Expand Down
96 changes: 69 additions & 27 deletions core/src/classpath/java/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1165,25 +1165,68 @@ private static synchronized String autoName(String name) {
//openjdk
private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
//openjdk
/**
* Returns an array of stack trace elements representing the stack dump
* of this thread. This method will return a zero-length array if
* this thread has not started or has terminated.
* If the returned array is of non-zero length then the first element of
* the array represents the top of the stack, which is the most recent
* method invocation in the sequence. The last element of the array
* represents the bottom of the stack, which is the least recent method
* invocation in the sequence.
*
* <p>If there is a security manager, and this thread is not
* the current thread, then the security manager's
* <tt>checkPermission</tt> method is called with a
* <tt>RuntimePermission("getStackTrace")</tt> permission
* to see if it's ok to get the stack trace.
*
* <p>Some virtual machines may, under some circumstances, omit one
* or more stack frames from the stack trace. In the extreme case,
* a virtual machine that has no stack trace information concerning
* this thread is permitted to return a zero-length array from this
* method.
*
* @return an array of <tt>StackTraceElement</tt>,
* each represents one stack frame.
*
* @throws SecurityException
* if a security manager exists and its
* <tt>checkPermission</tt> method doesn't allow
* getting the stack trace of thread.
* @see SecurityManager#checkPermission
* @see RuntimePermission
* @see Throwable#getStackTrace
*
* @since 1.5
*/
public StackTraceElement[] getStackTrace() {
if (this != Thread.currentThread()) {
// check for getStackTrace permission
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(new RuntimePermission("getStackTrace"));
security.checkPermission(
SecurityConstants.GET_STACK_TRACE_PERMISSION);
}
// optimization so we do not call into the vm for threads that
// have not yet started or have terminated
if (!isAlive()) {
return EMPTY_STACK_TRACE;
}
return getStackTrace0();
StackTraceElement[][] stackTraceArray = dumpThreads(new Thread[] {this});
StackTraceElement[] stackTrace = stackTraceArray[0];
// a thread that was alive during the previous isAlive call may have
// since terminated, therefore not having a stacktrace.
if (stackTrace == null) {
stackTrace = EMPTY_STACK_TRACE;
}
return stackTrace;
} else {
// Don't need JVM help for current thread
return (new Exception()).getStackTrace();
}
// Don't need JVM help for current thread
return (new Exception()).getStackTrace();
}
}

private native StackTraceElement[] getStackTrace0();

/**
* <p>
* This interface is used to handle uncaught exceptions
Expand Down Expand Up @@ -1268,18 +1311,19 @@ public enum State
}


/**
* Returns the current state of the thread. This
* is designed for monitoring thread behaviour, rather
* than for synchronization control.
*
* @return the current thread state.
*/
public State getState()
{
//todo implement
throw new UnsupportedClassVersionError();
}
//openjdk
/**
* Returns the state of this thread.
* This method is designed for use in monitoring of the system state,
* not for synchronization control.
*
* @return this thread's state.
* @since 1.5
*/
public State getState() {
// get current thread state
return sun.misc.VM.toThreadState(getThreadStatus());
}

//jnode + openjdk
static final ThreadGroup ROOT_GROUP;
Expand All @@ -1300,6 +1344,8 @@ public State getState()
ROOT_GROUP = g;
}

private native int getThreadStatus(); //jnode (TODO replace this by a private int attribute like in openjdk)

private static native void die0();

/**
Expand Down Expand Up @@ -1372,14 +1418,10 @@ public static Map<Thread, StackTraceElement[]> getAllStackTraces() {
return m;
}

private static StackTraceElement[][] dumpThreads(Thread[] threads) {
//todo implement it
throw new UnsupportedOperationException();
}
private static Thread[] getThreads() {
//todo implement it
throw new UnsupportedOperationException();
}
//openjdk
private native static StackTraceElement[][] dumpThreads(Thread[] threads);
//openjdk
private native static Thread[] getThreads();

/* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
*/
Expand Down