1999-04-07 16:42:40 +02:00
|
|
|
|
// natSystem.cc - Native code implementing System class.
|
|
|
|
|
|
2003-02-19 17:28:37 +01:00
|
|
|
|
/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
|
|
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>
|
2003-02-19 17:28:37 +01:00
|
|
|
|
#include <platform.h>
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
2001-01-09 08:07:51 +01:00
|
|
|
|
#include <stdio.h>
|
1999-04-07 16:42:40 +02:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
1999-09-11 00:03:10 +02:00
|
|
|
|
#include <gcj/cni.h>
|
1999-04-07 16:42:40 +02:00
|
|
|
|
#include <jvm.h>
|
|
|
|
|
#include <java/lang/System.h>
|
|
|
|
|
#include <java/lang/Class.h>
|
|
|
|
|
#include <java/lang/ArrayStoreException.h>
|
|
|
|
|
#include <java/lang/ArrayIndexOutOfBoundsException.h>
|
|
|
|
|
#include <java/lang/NullPointerException.h>
|
|
|
|
|
#include <java/io/PrintStream.h>
|
|
|
|
|
#include <java/io/InputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-05-13 22:10:37 +02:00
|
|
|
|
java::lang::System::setErr0 (java::io::PrintStream *newErr)
|
1999-04-07 16:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
err = newErr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2002-05-13 22:10:37 +02:00
|
|
|
|
java::lang::System::setIn0 (java::io::InputStream *newIn)
|
1999-04-07 16:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
in = newIn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2002-05-13 22:10:37 +02:00
|
|
|
|
java::lang::System::setOut0 (java::io::PrintStream *newOut)
|
1999-04-07 16:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
out = newOut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
java::lang::System::arraycopy (jobject src, jint src_offset,
|
|
|
|
|
jobject dst, jint dst_offset,
|
|
|
|
|
jint count)
|
|
|
|
|
{
|
|
|
|
|
if (! src || ! dst)
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
|
throw new NullPointerException;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
|
|
jclass src_c = src->getClass();
|
|
|
|
|
jclass dst_c = dst->getClass();
|
|
|
|
|
jclass src_comp = src_c->getComponentType();
|
|
|
|
|
jclass dst_comp = dst_c->getComponentType();
|
|
|
|
|
|
|
|
|
|
if (! src_c->isArray() || ! dst_c->isArray()
|
|
|
|
|
|| src_comp->isPrimitive() != dst_comp->isPrimitive()
|
|
|
|
|
|| (src_comp->isPrimitive() && src_comp != dst_comp))
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
|
throw new ArrayStoreException;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
|
|
__JArray *src_a = (__JArray *) src;
|
|
|
|
|
__JArray *dst_a = (__JArray *) dst;
|
|
|
|
|
if (src_offset < 0 || dst_offset < 0 || count < 0
|
2003-07-23 17:31:43 +02:00
|
|
|
|
|| (unsigned jint) src_offset > (unsigned jint) src_a->length
|
|
|
|
|
|| (unsigned jint) (src_offset + count) > (unsigned jint) src_a->length
|
|
|
|
|
|| (unsigned jint) dst_offset > (unsigned jint) dst_a->length
|
|
|
|
|
|| (unsigned jint) (dst_offset + count) > (unsigned jint) dst_a->length)
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
|
throw new ArrayIndexOutOfBoundsException;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
|
|
// Do-nothing cases.
|
|
|
|
|
if ((src == dst && src_offset == dst_offset)
|
|
|
|
|
|| ! count)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// If both are primitive, we can optimize trivially. If DST
|
|
|
|
|
// components are always assignable from SRC components, then we
|
|
|
|
|
// will never need to raise an error, and thus can do the
|
|
|
|
|
// optimization. If source and destinations are the same, then we
|
|
|
|
|
// know that the assignability premise always holds.
|
|
|
|
|
const bool prim = src_comp->isPrimitive();
|
|
|
|
|
if (prim || dst_comp->isAssignableFrom(src_comp) || src == dst)
|
|
|
|
|
{
|
1999-04-13 14:16:41 +02:00
|
|
|
|
const size_t size = (prim ? src_comp->size()
|
|
|
|
|
: sizeof elements((jobjectArray)src)[0]);
|
|
|
|
|
|
1999-11-25 01:36:51 +01:00
|
|
|
|
char *src_elts = _Jv_GetArrayElementFromElementType (src, src_comp);
|
1999-04-13 14:16:41 +02:00
|
|
|
|
src_elts += size * src_offset;
|
|
|
|
|
|
1999-11-25 01:36:51 +01:00
|
|
|
|
char *dst_elts = _Jv_GetArrayElementFromElementType (dst, dst_comp);
|
1999-04-13 14:16:41 +02:00
|
|
|
|
dst_elts += size * dst_offset;
|
|
|
|
|
|
1999-08-01 01:41:15 +02:00
|
|
|
|
#if HAVE_MEMMOVE
|
1999-04-07 16:42:40 +02:00
|
|
|
|
// We don't bother trying memcpy. It can't be worth the cost of
|
|
|
|
|
// the check.
|
1999-08-01 01:41:15 +02:00
|
|
|
|
// Don't cast to (void*), as memmove may expect (char*)
|
|
|
|
|
memmove (dst_elts, src_elts, count * size);
|
|
|
|
|
#else
|
|
|
|
|
bcopy (src_elts, dst_elts, count * size);
|
|
|
|
|
#endif
|
1999-04-07 16:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
jobject *src_elts = elements ((jobjectArray) src_a) + src_offset;
|
|
|
|
|
jobject *dst_elts = elements ((jobjectArray) dst_a) + dst_offset;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (*src_elts
|
|
|
|
|
&& ! dst_comp->isAssignableFrom((*src_elts)->getClass()))
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
|
throw new ArrayStoreException;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
*dst_elts++ = *src_elts++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jlong
|
|
|
|
|
java::lang::System::currentTimeMillis (void)
|
|
|
|
|
{
|
2002-03-08 02:03:56 +01:00
|
|
|
|
return _Jv_platform_gettimeofday ();
|
1999-04-07 16:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jint
|
|
|
|
|
java::lang::System::identityHashCode (jobject obj)
|
|
|
|
|
{
|
|
|
|
|
return _Jv_HashCode (obj);
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-13 22:10:37 +02:00
|
|
|
|
jboolean
|
|
|
|
|
java::lang::System::isWordsBigEndian (void)
|
1999-04-07 16:42:40 +02:00
|
|
|
|
{
|
2002-05-13 22:10:37 +02:00
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
long lval;
|
|
|
|
|
char cval;
|
|
|
|
|
} u;
|
|
|
|
|
|
|
|
|
|
u.lval = 1;
|
|
|
|
|
return u.cval == 0;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
}
|