Commit 42962a48 by Tom Tromey Committed by Tom Tromey

javaprims.h: Updated namespace declarations.

	* include/javaprims.h: Updated namespace declarations.
	* classes.pl (scan): Uniquify class list.
	* Makefile.in, configure: Rebuilt.
	* Makefile.am (nat_source_files): Added natConcreteProcess.cc.
	(built_java_source_files): New macro.
	(nat_headers): Added built_java_source_files.
	(javao_files): Likewise.
	(EXTRA_libgcj_la_SOURCES): Likewise.
	(libgcj.zip): Create built class files.
	($(built_java_source_files:.java=.class)): New target.
	(jv_convert_LDADD): Added -L$(here)/.libs.
	* configure.in: Create links for ConcreteProcess.java and
	natConcreteProcess.cc.
	* java/lang/Runtime.java (exec): Create a ConcreteProcess.
	* java/lang/natEcosProcess.cc: New file.
	* java/lang/EcosProcess.java: New file.
	* java/lang/PosixProcess.java: New file.
	* java/lang/natPosixProcess.cc: New file.

From-SVN: r26901
parent 3b551e09
1999-05-12 Tom Tromey <tromey@cygnus.com>
* include/javaprims.h: Updated namespace declarations.
* classes.pl (scan): Uniquify class list.
* Makefile.in, configure: Rebuilt.
* Makefile.am (nat_source_files): Added natConcreteProcess.cc.
(built_java_source_files): New macro.
(nat_headers): Added built_java_source_files.
(javao_files): Likewise.
(EXTRA_libgcj_la_SOURCES): Likewise.
(libgcj.zip): Create built class files.
($(built_java_source_files:.java=.class)): New target.
(jv_convert_LDADD): Added -L$(here)/.libs.
* configure.in: Create links for ConcreteProcess.java and
natConcreteProcess.cc.
* java/lang/Runtime.java (exec): Create a ConcreteProcess.
* java/lang/natEcosProcess.cc: New file.
* java/lang/EcosProcess.java: New file.
* java/lang/PosixProcess.java: New file.
* java/lang/natPosixProcess.cc: New file.
1999-05-12 Warren Levy <warrenl@cygnus.com>
* java/net/PlainSocketImpl.java: Corrected copyright & header comments.
......
......@@ -85,11 +85,12 @@ nat_files = $(nat_source_files:.cc=.lo)
## Objects from C sources in subdirs.
c_files = $(c_source_files:.c=.lo)
## Objects from Java sources in subdirs.
javao_files = $(java_source_files:.java=.lo)
javao_files = $(java_source_files:.java=.lo) \
$(built_java_source_files:.java=.lo)
libgcj_la_SOURCES = prims.cc jni.cc exception.cc
EXTRA_libgcj_la_SOURCES = boehm.cc nogc.cc posix-threads.cc no-threads.cc \
$(c_source_files) $(java_source_files)
$(c_source_files) $(java_source_files) $(built_java_source_files)
libgcj_la_DEPENDENCIES = libgcj.zip $(javao_files) $(nat_files) \
$(c_files) $(GCOBJS) $(THREADOBJS)
libgcj_la_LIBADD = $(javao_files) $(nat_files) $(c_files) $(GCOBJS) \
......@@ -106,6 +107,14 @@ libgcj_la_LDFLAGS = -rpath $(toolexeclibdir) \
## hand-maintained headers.
$(java_source_files:.java=.class): libgcj.zip
## FIXME: this isn't really correct.
$(built_java_source_files:.java=.class): $(built_java_source_files)
## This little nastiness is here so that the backquoted stuff in the
## GCJ definition can be correctly expanded, if required.
javac="$(JAVAC)"; \
$$javac $(JCFLAGS) -classpath $(here):`cd $(srcdir) && /bin/pwd` \
-d $(here) $?
## We have the zip file depend on the java sources and not the class
## files, because we don't know the names of all the class files.
## FIXME: this method fails in a peculiar case: if libgcj.zip is
......@@ -113,6 +122,9 @@ $(java_source_files:.java=.class): libgcj.zip
## `make libgcj.zip' will not rebuilt foo.class. That's because
## libgcj.zip is not out-of-date with respect to foo.java.
libgcj.zip: $(java_source_files)
## FIXME: this ought to depend on built_java_source_files, but right
## now it can't. Ugly.
$(MAKE) $(built_java_source_files:.java=.class)
## This little nastiness is here so that the backquoted stuff in the
## GCJ definition can be correctly expanded, if required.
javac="$(JAVAC)"; cd $(srcdir); \
......@@ -168,7 +180,8 @@ $(javao_files): %.lo: %.java
$(GCJH) -classpath $(top_builddir) $(basename $<)
## Header files used when compiling some of the nat* files.
nat_headers = $(ordinary_java_source_files:.java=.h)
nat_headers = $(ordinary_java_source_files:.java=.h) \
$(built_java_source_files:.java=.h)
$(nat_headers): libgcj.zip
......@@ -268,8 +281,10 @@ jv_convert_LINK = $(LIBTOOL) --mode=link $(GCJ) $(JC1FLAGS) $(LDFLAGS) \
## We explicitly link in the libraries we need. This way we don't
## need -nodefaultlibs, so we can still rely on gcj picking up the
## system libraries we need (via the specs file).
## We need the -L so that gcj can find libgcj with `-lgcj'.
## FIXME: should be _libs on some systems.
jv_convert_LDADD = $(convert_source_files:.java=.lo) libgcj.la \
$(GCLIBS) $(THREADLIBS) $(ZLIBS)
$(GCLIBS) $(THREADLIBS) $(ZLIBS) -L$(here)/.libs
## Depend on the spec file to make sure it is up to date before
## linking this program.
jv_convert_DEPENDENCIES = $(convert_source_files:.java=.lo) \
......@@ -411,6 +426,10 @@ java/awt/peer/WindowPeer.java
# $(awt_java_source_files)
## Java files which are created by configure and thus are in the build
## directory.
built_java_source_files = java/lang/ConcreteProcess.java
## List of all .java files to be compiled. Please keep this list
## alphabetical. Please put files from gnu/gcj/convert into
## convert_source_files. If the .java file has a hand-maintained
......@@ -679,6 +698,7 @@ java/io/natFile.cc \
java/io/natFileDescriptor.cc \
java/lang/natCharacter.cc \
java/lang/natClass.cc \
java/lang/natConcreteProcess.cc \
java/lang/natDouble.cc \
java/lang/natFirstThread.cc \
java/lang/natFloat.cc \
......
......@@ -156,11 +156,13 @@ INCLUDES = -Iinclude -I$(top_srcdir)/include $(GCINCS) $(THREADINCS) $(EH_COMMON
nat_files = $(nat_source_files:.cc=.lo)
c_files = $(c_source_files:.c=.lo)
javao_files = $(java_source_files:.java=.lo)
javao_files = $(java_source_files:.java=.lo) \
$(built_java_source_files:.java=.lo)
libgcj_la_SOURCES = prims.cc jni.cc exception.cc
EXTRA_libgcj_la_SOURCES = boehm.cc nogc.cc posix-threads.cc no-threads.cc \
$(c_source_files) $(java_source_files)
$(c_source_files) $(java_source_files) $(built_java_source_files)
libgcj_la_DEPENDENCIES = libgcj.zip $(javao_files) $(nat_files) \
$(c_files) $(GCOBJS) $(THREADOBJS)
......@@ -177,7 +179,9 @@ CLEANFILES = libgcj.zip
SUFFIXES = .class .java .h
nat_headers = $(ordinary_java_source_files:.java=.h)
nat_headers = $(ordinary_java_source_files:.java=.h) \
$(built_java_source_files:.java=.h)
FTFRIEND = void JvRunMain (jclass klass, int argc, const char **argv)
......@@ -279,6 +283,8 @@ java/awt/peer/WindowPeer.java
# $(awt_java_source_files)
built_java_source_files = java/lang/ConcreteProcess.java
ordinary_java_source_files = $(convert_source_files) \
gnu/gcj/text/BaseBreakIterator.java \
gnu/gcj/text/CharacterBreakIterator.java \
......@@ -543,6 +549,7 @@ java/io/natFile.cc \
java/io/natFileDescriptor.cc \
java/lang/natCharacter.cc \
java/lang/natClass.cc \
java/lang/natConcreteProcess.cc \
java/lang/natDouble.cc \
java/lang/natFirstThread.cc \
java/lang/natFloat.cc \
......@@ -721,8 +728,9 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/java/lang/ClassNotFoundException.P \
.deps/java/lang/CloneNotSupportedException.P \
.deps/java/lang/Cloneable.P .deps/java/lang/Comparable.P \
.deps/java/lang/Compiler.P .deps/java/lang/Double.P \
.deps/java/lang/Error.P .deps/java/lang/Exception.P \
.deps/java/lang/Compiler.P .deps/java/lang/ConcreteProcess.P \
.deps/java/lang/Double.P .deps/java/lang/Error.P \
.deps/java/lang/Exception.P \
.deps/java/lang/ExceptionInInitializerError.P \
.deps/java/lang/FirstThread.P .deps/java/lang/Float.P \
.deps/java/lang/IllegalAccessError.P \
......@@ -1341,7 +1349,13 @@ maintainer-clean-generic clean mostlyclean distclean maintainer-clean
$(java_source_files:.java=.class): libgcj.zip
$(built_java_source_files:.java=.class): $(built_java_source_files)
javac="$(JAVAC)"; \
$$javac $(JCFLAGS) -classpath $(here):`cd $(srcdir) && /bin/pwd` \
-d $(here) $?
libgcj.zip: $(java_source_files)
$(MAKE) $(built_java_source_files:.java=.class)
javac="$(JAVAC)"; cd $(srcdir); \
$$javac $(JCFLAGS) -classpath $(here):`/bin/pwd` -d $(here) \
$(subst $(srcdir)/,,$?)
......
......@@ -36,7 +36,7 @@ sub scan
{
local ($dir, $indent) = @_;
local (@subdirs) = ();
local (@classes) = ();
local (%classes) = ();
local ($d) = new DirHandle $dir;
local (*JFILE);
......@@ -72,7 +72,7 @@ sub scan
# For now assume that class names start with upper
# case letter.
next unless /(class|interface) ([A-Z][A-Za-z0-9]+)/;
push (@classes, $2);
$classes{$2} = 1;
}
close (FILE);
}
......@@ -86,7 +86,7 @@ sub scan
print $spaces, "namespace ", $classname, "\n";
print $spaces, "{\n";
foreach (sort @classes)
foreach (sort keys %classes)
{
print $spaces, " class ", $_, ";\n";
}
......
......@@ -55,9 +55,11 @@ TARGET_ECOS="$with_ecos"
case "$TARGET_ECOS" in
no)
FILE_DESCRIPTOR=natFileDescriptorPosix.cc
PROCESS=Posix
;;
*)
FILE_DESCRIPTOR=natFileDescriptorEcos.cc
PROCESS=Ecos
AC_DEFINE(ECOS)
;;
esac
......@@ -76,6 +78,11 @@ test -d java || mkdir java
test -d java/io || mkdir java/io
AC_LINK_FILES(java/io/$FILE_DESCRIPTOR, java/io/natFileDescriptor.cc)
dnl Likewise for ConcreteProcess.java and natConcreteProcess.cc.
test -d java/lang || mkdir java/lang
AC_LINK_FILES(java/lang/${PROCESS}Process.java, java/lang/ConcreteProcess.java)
AC_LINK_FILES(java/lang/nat${PROCESS}Process.cc, java/lang/natConcreteProcess.cc)
SYSTEMSPEC=
AC_SUBST(SYSTEMSPEC)
......
......@@ -106,6 +106,7 @@ extern "Java"
class Cloneable;
class Comparable;
class Compiler;
class ConcreteProcess;
class Double;
class Error;
class Exception;
......@@ -161,7 +162,6 @@ extern "Java"
class VerifyError;
class VirtualMachineError;
class Void;
namespace reflect
{
class AccessibleObject;
......@@ -197,6 +197,7 @@ extern "Java"
class Observable;
class Observer;
class Properties;
class PropertyResourceBundle;
class Random;
class ResourceBundle;
class SimpleTimeZone;
......@@ -206,7 +207,6 @@ extern "Java"
class TooManyListenersException;
class Vector;
class VectorEnumeration;
namespace zip
{
class Adler32;
......@@ -214,11 +214,13 @@ extern "Java"
class Checksum;
class Deflater;
class DeflaterOutputStream;
class InflaterInputStream;
class ZipConstants;
class ZipEntry;
class ZipEnumeration;
class ZipException;
class ZipFile;
class ZipInputStream;
class ZipOutputStream;
};
};
......
// EcosProcess.java - Subclass of Process for eCos systems.
/* Copyright (C) 1998, 1999 Cygnus Solutions
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.lang;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date May 11, 1999
*/
// This is entirely internal to our implementation.
// This file is copied to `ConcreteProcess.java' before compilation.
// Hence the class name apparently does not match the file name.
final class ConcreteProcess extends Process
{
// See natEcosProcess.cc to understand why this is native.
public native void destroy ();
public int exitValue ()
{
return 0;
}
public InputStream getErrorStream ()
{
return null;
}
public InputStream getInputStream ()
{
return null;
}
public OutputStream getOutputStream ()
{
return null;
}
public int waitFor () throws InterruptedException
{
return 0;
}
public ConcreteProcess (String[] progarray, String[] envp) throws IOException
{
throw new IOException ("eCos processes unimplemented");
}
}
// PosixProcess.java - Subclass of Process for POSIX systems.
/* Copyright (C) 1998, 1999 Cygnus Solutions
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.lang;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date May 3, 1999
*/
// This is entirely internal to our implementation.
// This file is copied to `ConcreteProcess.java' before compilation.
// Hence the class name apparently does not match the file name.
final class ConcreteProcess extends Process
{
public native void destroy ();
public native int exitValue ();
public InputStream getErrorStream ()
{
return errorStream;
}
public InputStream getInputStream ()
{
return inputStream;
}
public OutputStream getOutputStream ()
{
return outputStream;
}
public native int waitFor () throws InterruptedException;
// This is used for actual initialization, as we can't write a
// native constructor.
public native void startProcess (String[] progarray, String[] envp)
throws IOException;
// This file is copied to `ConcreteProcess.java' before
// compilation. Hence the constructor name apparently does not
// match the file name.
public ConcreteProcess (String[] progarray, String[] envp) throws IOException
{
startProcess (progarray, envp);
}
// The process id. This is cast to a pid_t on the native side.
private long pid;
// True when child has exited.
private boolean hasExited;
// The exit status, if the child has exited.
private int status;
// The streams.
private InputStream errorStream;
private InputStream inputStream;
private OutputStream outputStream;
}
......@@ -52,8 +52,7 @@ public class Runtime
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkExec(progarray[0]);
// FIXME.
return null;
return new ConcreteProcess (progarray, envp);
}
private final static void checkExit (int status)
......
// natEcosProcess.cc - Native side of eCos processes.
/* Copyright (C) 1998, 1999 Cygnus Solutions
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
// The configury system needs this file to exist, since we can't
// really conditionally link files (an autoconf bug). To avoid having
// an empty translation unit, we make a single method native. FIXME.
#include <config.h>
#include <cni.h>
#include <jvm.h>
#include <java/lang/ConcreteProcess.h>
void
java::lang::ConcreteProcess::destroy (void)
{
}
// natPosixProcess.cc - Native side of POSIX process code.
/* Copyright (C) 1998, 1999 Cygnus Solutions
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <cni.h>
#include <jvm.h>
#include <java/lang/ConcreteProcess.h>
#include <java/lang/IllegalThreadStateException.h>
#include <java/lang/InterruptedException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/Thread.h>
#include <java/io/FileDescriptor.h>
#include <java/io/FileInputStream.h>
#include <java/io/FileOutputStream.h>
#include <java/io/IOException.h>
extern char **environ;
void
java::lang::ConcreteProcess::destroy (void)
{
if (! hasExited)
{
// Really kill it.
kill ((pid_t) pid, SIGKILL);
}
}
jint
java::lang::ConcreteProcess::exitValue (void)
{
if (! hasExited)
{
int wstat;
pid_t r = waitpid ((pid_t) pid, &wstat, WNOHANG);
if (r == -1)
{
jstring x = JvNewStringLatin1 (strerror (errno));
_Jv_Throw (new IllegalThreadStateException (x));
}
hasExited = true;
// Just use the raw status. FIXME: what is right?
status = wstat;
}
return status;
}
jint
java::lang::ConcreteProcess::waitFor (void)
{
if (! hasExited)
{
int wstat;
int r = waitpid ((pid_t) pid, &wstat, 0);
if (r != -1)
{
hasExited = true;
// Just use the raw status. FIXME: what is right?
status = wstat;
}
if (java::lang::Thread::interrupted())
_Jv_Throw (new InterruptedException (JvNewStringLatin1 ("wait interrupted")));
}
return status;
}
static char *
new_string (jstring string)
{
jsize s = _Jv_GetStringUTFLength (string);
char *buf = (char *) _Jv_Malloc (s + 1);
_Jv_GetStringUTFRegion (string, 0, s, buf);
buf[s] = '\0';
return buf;
}
void
java::lang::ConcreteProcess::startProcess (jstringArray progarray,
jstringArray envp)
{
using namespace java::io;
hasExited = false;
if (! progarray)
_Jv_Throw (new NullPointerException);
// Transform arrays to native form.
// FIXME: we use malloc here. We shouldn't. If an exception is
// thrown we will leak memory.
char **args = (char **) _Jv_Malloc ((progarray->length + 1)
* sizeof (char *));
char **env = NULL;
if (envp)
env = (char **) _Jv_Malloc ((envp->length + 1) * sizeof (char *));
// for (int i = 0; i < progarray->length; ++i)
// args[i] = NULL;
// for (int i = 0; i < envp->length; ++i)
// env[i] = NULL;
// FIXME: GC will fail here if _Jv_Malloc throws an exception.
// That's because we have to manually free the contents, but we
jstring *elts = elements (progarray);
for (int i = 0; i < progarray->length; ++i)
args[i] = new_string (elts[i]);
args[progarray->length] = NULL;
if (envp)
{
elts = elements (envp);
for (int i = 0; i < envp->length; ++i)
args[i] = new_string (elts[i]);
args[envp->length] = NULL;
}
// Create pipes for I/O.
int inp[2], outp[2], errp[2];
if (pipe (inp)
|| pipe (outp)
|| pipe (errp))
{
ioerror:
// FIXME.
_Jv_Free (args);
if (env)
_Jv_Free (env);
_Jv_Throw (new IOException (JvNewStringLatin1 (strerror (errno))));
}
// We create the streams before forking. Otherwise if we had an
// error while creating the streams we would have run the child with
// no way to communicate with it.
errorStream = new FileInputStream (new FileDescriptor (errp[0]));
inputStream = new FileInputStream (new FileDescriptor (inp[0]));
outputStream = new FileOutputStream (new FileDescriptor (outp[1]));
// We don't use vfork() because that would cause the local
// environment to be set by the child.
if ((pid = (jlong) fork ()) == -1)
goto ioerror;
if (pid == 0)
{
// Child process, so remap descriptors and exec.
if (envp)
environ = env;
// We ignore errors from dup2 because they should never occur.
dup2 (outp[0], 0);
dup2 (inp[1], 1);
dup2 (errp[1], 2);
close (inp[0]);
close (inp[1]);
close (errp[0]);
close (errp[1]);
close (outp[0]);
close (outp[1]);
environ = env;
execvp (args[0], args);
_exit (127);
}
// Parent. Close extra file descriptors and mark ours as
// close-on-exec.
close (outp[0]);
close (inp[1]);
close (errp[1]);
fcntl (outp[1], F_SETFD, 1);
fcntl (inp[0], F_SETFD, 1);
fcntl (errp[0], F_SETFD, 1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment