OSDN Git Service

* Merged gcj-abi-2-dev-branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / gcj / javaprims.h
1 // javaprims.h - Main external header file for libgcj.  -*- c++ -*-
2
3
4 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
5    Free Software Foundation
6
7    This file is part of libgcj.
8
9 This software is copyrighted work licensed under the terms of the
10 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
11 details.  */
12
13 #ifndef __JAVAPRIMS_H__
14 #define __JAVAPRIMS_H__
15
16 // Force C++ compiler to use Java-style exceptions.
17 #pragma GCC java_exceptions
18
19 #include <gcj/libgcj-config.h>
20
21 // FIXME: this is a hack until we get a proper gcjh.
22 // It is needed to work around system header files that define TRUE
23 // and FALSE.
24 #undef TRUE
25 #define TRUE TRUE
26 #undef FALSE
27 #define FALSE FALSE
28
29 // To force selection of correct types that will mangle consistently
30 // across platforms.
31 extern "Java"
32 {
33   typedef __java_byte jbyte;
34   typedef __java_short jshort;
35   typedef __java_int jint;
36   typedef __java_long jlong;
37   typedef __java_float jfloat;
38   typedef __java_double jdouble;
39   typedef __java_char jchar;
40   typedef __java_boolean jboolean;
41   typedef jint jsize;
42
43   // The following class declarations are automatically generated by
44   // the `classes.pl' script.
45   namespace java
46   {
47     namespace io
48     {
49       class BufferedInputStream;
50       class BufferedOutputStream;
51       class BufferedReader;
52       class BufferedWriter;
53       class ByteArrayInputStream;
54       class ByteArrayOutputStream;
55       class CharArrayReader;
56       class CharArrayWriter;
57       class CharConversionException;
58       class DataInput;
59       class DataInputStream;
60       class DataOutput;
61       class DataOutputStream;
62       class EOFException;
63       class Externalizable;
64       class File;
65       class FileDescriptor;
66       class FileFilter;
67       class FileInputStream;
68       class FileNotFoundException;
69       class FileOutputStream;
70       class FilePermission;
71       class FileReader;
72       class FileWriter;
73       class FilenameFilter;
74       class FilterInputStream;
75       class FilterOutputStream;
76       class FilterReader;
77       class FilterWriter;
78       class IOException;
79       class InputStream;
80       class InputStreamReader;
81       class InterfaceComparator;
82       class InterruptedIOException;
83       class InvalidClassException;
84       class InvalidObjectException;
85       class LineNumberInputStream;
86       class LineNumberReader;
87       class MemberComparator;
88       class MyIOException;
89       class NotActiveException;
90       class NotSerializableException;
91       class ObjectInput;
92       class ObjectInputStream;
93       class ObjectInputStream$GetField;
94       class ObjectInputValidation;
95       class ObjectOutput;
96       class ObjectOutputStream;
97       class ObjectOutputStream$PutField;
98       class ObjectStreamClass;
99       class ObjectStreamConstants;
100       class ObjectStreamException;
101       class ObjectStreamField;
102       class OptionalDataException;
103       class OutputStream;
104       class OutputStreamWriter;
105       class PipedInputStream;
106       class PipedOutputStream;
107       class PipedReader;
108       class PipedWriter;
109       class PrintStream;
110       class PrintWriter;
111       class PushbackInputStream;
112       class PushbackReader;
113       class RandomAccessFile;
114       class Reader;
115       class SequenceInputStream;
116       class Serializable;
117       class SerializablePermission;
118       class StreamCorruptedException;
119       class StreamTokenizer;
120       class StringBufferInputStream;
121       class StringReader;
122       class StringWriter;
123       class SyncFailedException;
124       class UTFDataFormatException;
125       class UnsupportedEncodingException;
126       class VMObjectStreamClass;
127       class ValidatorAndPriority;
128       class WriteAbortedException;
129       class Writer;
130     }
131
132     namespace lang
133     {
134       class AbstractMethodError;
135       class ArithmeticException;
136       class ArrayIndexOutOfBoundsException;
137       class ArrayStoreException;
138       class AssertionError;
139       class Boolean;
140       class Byte;
141       class CharSequence;
142       class Character;
143       class Character$Subset;
144       class Character$UnicodeBlock;
145       class Class;
146       class ClassCastException;
147       class ClassCircularityError;
148       class ClassFormatError;
149       class ClassLoader;
150       class ClassNotFoundException;
151       class CloneNotSupportedException;
152       class Cloneable;
153       class Comparable;
154       class Compiler;
155       class ConcreteProcess;
156       class ConcreteProcess$EOFInputStream;
157       class ConcreteProcess$ProcessManager;
158       class Double;
159       class Error;
160       class Exception;
161       class ExceptionInInitializerError;
162       class Float;
163       class IllegalAccessError;
164       class IllegalAccessException;
165       class IllegalArgumentException;
166       class IllegalMonitorStateException;
167       class IllegalStateException;
168       class IllegalThreadStateException;
169       class IncompatibleClassChangeError;
170       class IndexOutOfBoundsException;
171       class InheritableThreadLocal;
172       class InstantiationError;
173       class InstantiationException;
174       class Integer;
175       class InternalError;
176       class InterruptedException;
177       class LinkageError;
178       class Long;
179       class Math;
180       class NegativeArraySizeException;
181       class NoClassDefFoundError;
182       class NoSuchFieldError;
183       class NoSuchFieldException;
184       class NoSuchMethodError;
185       class NoSuchMethodException;
186       class NullPointerException;
187       class Number;
188       class NumberFormatException;
189       class Object;
190       class OutOfMemoryError;
191       class Package;
192       class Process;
193       class Runnable;
194       class Runtime;
195       class RuntimeException;
196       class RuntimePermission;
197       class SecurityContext;
198       class SecurityException;
199       class SecurityManager;
200       class Short;
201       class StackOverflowError;
202       class StackTraceElement;
203       class StrictMath;
204       class String;
205       class String$CaseInsensitiveComparator;
206       class StringBuffer;
207       class StringIndexOutOfBoundsException;
208       class System;
209       class Thread;
210       class ThreadDeath;
211       class ThreadGroup;
212       class ThreadLocal;
213       class Throwable;
214       class UnknownError;
215       class UnsatisfiedLinkError;
216       class UnsupportedClassVersionError;
217       class UnsupportedOperationException;
218       class VMClassLoader;
219       class VMCompiler;
220       class VMSecurityManager;
221       class VMThrowable;
222       class VerifyError;
223       class VirtualMachineError;
224       class Void;
225       namespace ref
226       {
227         class PhantomReference;
228         class Reference;
229         class ReferenceQueue;
230         class SoftReference;
231         class WeakReference;
232       }
233
234       namespace reflect
235       {
236         class AccessibleObject;
237         class Array;
238         class Constructor;
239         class Field;
240         class InvocationHandler;
241         class InvocationTargetException;
242         class Member;
243         class Method;
244         class Modifier;
245         class Proxy;
246         class Proxy$ClassFactory;
247         class Proxy$ProxyData;
248         class Proxy$ProxySignature;
249         class Proxy$ProxyType;
250         class ReflectPermission;
251         class UndeclaredThrowableException;
252       }
253     }
254
255     namespace util
256     {
257       class AbstractCollection;
258       class AbstractList;
259       class AbstractMap;
260       class AbstractMap$BasicMapEntry;
261       class AbstractSequentialList;
262       class AbstractSet;
263       class ArrayList;
264       class Arrays;
265       class Arrays$ArrayList;
266       class BitSet;
267       class Calendar;
268       class Collection;
269       class Collections;
270       class Collections$CopiesList;
271       class Collections$EmptyList;
272       class Collections$EmptyMap;
273       class Collections$EmptySet;
274       class Collections$ReverseComparator;
275       class Collections$SingletonList;
276       class Collections$SingletonMap;
277       class Collections$SingletonSet;
278       class Collections$SynchronizedCollection;
279       class Collections$SynchronizedIterator;
280       class Collections$SynchronizedList;
281       class Collections$SynchronizedListIterator;
282       class Collections$SynchronizedMap;
283       class Collections$SynchronizedMapEntry;
284       class Collections$SynchronizedRandomAccessList;
285       class Collections$SynchronizedSet;
286       class Collections$SynchronizedSortedMap;
287       class Collections$SynchronizedSortedSet;
288       class Collections$UnmodifiableCollection;
289       class Collections$UnmodifiableEntrySet;
290       class Collections$UnmodifiableIterator;
291       class Collections$UnmodifiableList;
292       class Collections$UnmodifiableListIterator;
293       class Collections$UnmodifiableMap;
294       class Collections$UnmodifiableRandomAccessList;
295       class Collections$UnmodifiableSet;
296       class Collections$UnmodifiableSortedMap;
297       class Collections$UnmodifiableSortedSet;
298       class Comparator;
299       class ConcurrentModificationException;
300       class Currency;
301       class Date;
302       class Dictionary;
303       class EmptyStackException;
304       class Enumeration;
305       class EventListener;
306       class EventListenerProxy;
307       class EventObject;
308       class GregorianCalendar;
309       class HashMap;
310       class HashMap$HashEntry;
311       class HashMap$HashIterator;
312       class HashSet;
313       class Hashtable;
314       class Hashtable$Enumerator;
315       class Hashtable$HashEntry;
316       class Hashtable$HashIterator;
317       class IdentityHashMap;
318       class IdentityHashMap$IdentityEntry;
319       class IdentityHashMap$IdentityIterator;
320       class Iterator;
321       class LinkedHashMap;
322       class LinkedHashMap$LinkedHashEntry;
323       class LinkedHashSet;
324       class LinkedList;
325       class LinkedList$Entry;
326       class LinkedList$LinkedListItr;
327       class List;
328       class ListIterator;
329       class ListResourceBundle;
330       class Locale;
331       class Map;
332       class Map$Entry;
333       class Map$Map;
334       class MissingResourceException;
335       class MyResources;
336       class NoSuchElementException;
337       class Observable;
338       class Observer;
339       class Properties;
340       class PropertyPermission;
341       class PropertyPermissionCollection;
342       class PropertyResourceBundle;
343       class Random;
344       class RandomAccess;
345       class RandomAccessSubList;
346       class ResourceBundle;
347       class ResourceBundle$BundleKey;
348       class Set;
349       class SimpleTimeZone;
350       class SortedMap;
351       class SortedSet;
352       class Stack;
353       class StringTokenizer;
354       class SubList;
355       class TimeZone;
356       class Timer;
357       class Timer$Scheduler;
358       class Timer$TaskQueue;
359       class TimerTask;
360       class TooManyListenersException;
361       class TreeMap;
362       class TreeMap$Node;
363       class TreeMap$SubMap;
364       class TreeMap$TreeIterator;
365       class TreeSet;
366       class VMTimeZone;
367       class Vector;
368       class WeakHashMap;
369       class WeakHashMap$WeakBucket;
370       class WeakHashMap$WeakEntry;
371       class WeakHashMap$WeakEntrySet;
372       namespace jar
373       {
374         class Attributes;
375         class Attributes$Name;
376         class JarEntry;
377         class JarException;
378         class JarFile;
379         class JarFile$JarEnumeration;
380         class JarInputStream;
381         class JarOutputStream;
382         class Manifest;
383       }
384
385       namespace logging
386       {
387         class ConsoleHandler;
388         class ErrorManager;
389         class FileHandler;
390         class Filter;
391         class Formatter;
392         class Handler;
393         class Level;
394         class LogManager;
395         class LogRecord;
396         class Logger;
397         class LoggingPermission;
398         class MemoryHandler;
399         class SimpleFormatter;
400         class SocketHandler;
401         class StreamHandler;
402         class XMLFormatter;
403       }
404
405       namespace prefs
406       {
407         class AbstractPreferences;
408         class BackingStoreException;
409         class InvalidPreferencesFormatException;
410         class NodeChangeEvent;
411         class NodeChangeListener;
412         class PreferenceChangeEvent;
413         class PreferenceChangeListener;
414         class Preferences;
415         class PreferencesFactory;
416       }
417
418       namespace regex
419       {
420         class Matcher;
421         class Pattern;
422         class PatternSyntaxException;
423       }
424
425       namespace zip
426       {
427         class Adler32;
428         class CRC32;
429         class CheckedInputStream;
430         class CheckedOutputStream;
431         class Checksum;
432         class DataFormatException;
433         class Deflater;
434         class DeflaterOutputStream;
435         class GZIPInputStream;
436         class GZIPOutputStream;
437         class Inflater;
438         class InflaterInputStream;
439         class ZipConstants;
440         class ZipEntry;
441         class ZipException;
442         class ZipFile;
443         class ZipFile$PartialInputStream;
444         class ZipFile$ZipEntryEnumeration;
445         class ZipInputStream;
446         class ZipOutputStream;
447       }
448     }
449   }
450 }
451   
452 typedef struct java::lang::Object* jobject;
453 typedef class java::lang::Class* jclass;
454 typedef class java::lang::Throwable* jthrowable;
455 typedef class java::lang::String* jstring;
456 struct _Jv_JNIEnv;
457
458 typedef struct _Jv_Field *jfieldID;
459 typedef struct _Jv_Method *jmethodID;
460
461 extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__));
462 extern "C" jobject _Jv_AllocObjectNoFinalizer (jclass) __attribute__((__malloc__));
463 extern "C" jobject _Jv_AllocObjectNoInitNoFinalizer (jclass) __attribute__((__malloc__));
464 #ifdef JV_HASH_SYNCHRONIZATION
465   extern "C" jobject _Jv_AllocPtrFreeObject (jclass)
466                             __attribute__((__malloc__));
467 #else
468   // Collector still needs to scan sync_info
469   static inline jobject _Jv_AllocPtrFreeObject (jclass klass)
470   {
471     return _Jv_AllocObject(klass);
472   }
473 #endif
474 extern "C" jboolean _Jv_IsInstanceOf(jobject, jclass);
475 extern "C" jstring _Jv_AllocString(jsize) __attribute__((__malloc__));
476 extern "C" jstring _Jv_NewString (const jchar*, jsize)
477   __attribute__((__malloc__));
478 extern jint _Jv_FormatInt (jchar* bufend, jint num);
479 extern "C" jchar* _Jv_GetStringChars (jstring str);
480 extern "C" void _Jv_MonitorEnter (jobject);
481 extern "C" void _Jv_MonitorExit (jobject);
482 extern "C" jstring _Jv_NewStringUTF (const char *bytes)
483   __attribute__((__malloc__));
484 extern "C" jstring _Jv_NewStringLatin1(const char*, jsize)
485   __attribute__((__malloc__));
486 extern "C" jsize _Jv_GetStringUTFLength (jstring);
487 extern "C" jsize _Jv_GetStringUTFRegion (jstring, jsize, jsize, char *);
488 extern "C" jint _Jv_hashUtf8String (char*, int);
489
490 extern jint _Jv_CreateJavaVM (void* /*vm_args*/);
491
492 void
493 _Jv_ThreadRun (java::lang::Thread* thread);
494 jint
495 _Jv_AttachCurrentThread(java::lang::Thread* thread);
496 extern "C" java::lang::Thread*
497 _Jv_AttachCurrentThread(jstring name, java::lang::ThreadGroup* group);
498 extern "C" java::lang::Thread*
499 _Jv_AttachCurrentThreadAsDaemon(jstring name, java::lang::ThreadGroup* group);
500 extern "C" jint _Jv_DetachCurrentThread (void);
501
502 extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__));
503 extern "C" void* _Jv_Malloc (jsize) __attribute__((__malloc__));
504 extern "C" void* _Jv_Realloc (void *, jsize);
505 extern "C" void _Jv_Free (void*);
506 extern void (*_Jv_RegisterClassHook) (jclass cl);
507 extern "C" void _Jv_RegisterClassHookDefault (jclass);
508
509 typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__)));
510 typedef unsigned int _Jv_uint __attribute__((__mode__(__SI__)));
511 typedef unsigned int _Jv_ulong __attribute__((__mode__(__DI__)));
512
513 class _Jv_Utf8Const
514 {
515   _Jv_ushort hash;
516   _Jv_ushort length;    /* In bytes, of data portion, without final '\0'. */
517   char data[1];         /* In Utf8 format, with final '\0'. */
518  public:
519   /** Return same value of java.lang.String's hashCode. */
520   jint hash32() { return _Jv_hashUtf8String(data, length); }
521   /** Return a hash code that has at least 16 bits of information. */
522   _Jv_ushort hash16 () { return hash; }
523   /** Return a hash code that has at least 8 bits of information. */
524   _Jv_ushort hash8 () { return hash; }
525   /** Length in bytes of the UTF8-encoding. */
526   _Jv_ushort len () const { return length; }
527   /** Pointer to the first byte in the NUL-terminated UTF8-encoding. */
528   char* chars() { return data; }
529   /** Pointer to the NUL byte that terminated the UTF8-encoding. */
530   char* limit() { return data+length; }
531   /** Return the first byte in the UTF8-encoding. */
532   char first() const { return data[0]; }
533   /** Create a (non-interned) java.lang.String from this UTF8Const. */
534   jstring toString() { return _Jv_NewStringUTF(data); }
535   /** Given an UTF8 string, how many bytes needed for a UTF8Const,
536       including struct header, and final NUL.  I.e. what to pas to malloc. */
537   static int space_needed (char *, int len)
538   { return sizeof (_Jv_Utf8Const) + len + 1; }
539   /** Given an allocated _Jv_Utf8Const, copy / fill it in. */
540   void init (char *s, int len);
541   friend jboolean _Jv_equalUtf8Consts (const _Jv_Utf8Const*, const _Jv_Utf8Const *);
542   friend jboolean _Jv_equal (_Jv_Utf8Const*, jstring, jint);
543   friend jboolean _Jv_equaln (_Jv_Utf8Const*, jstring, jint);
544   friend _Jv_Utf8Const *_Jv_makeUtf8Const (char*, int);
545   friend _Jv_Utf8Const *_Jv_makeUtf8Const (jstring);
546   friend jstring _Jv_NewStringUtf8Const (_Jv_Utf8Const*);
547 };
548
549
550 #endif /* __JAVAPRIMS_H__ */