04f99edd68ccacc420f892eaa2cc427d379d73a2
[platform/upstream/gcc.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, 2005, 2006
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 Closeable;
59       class DataInput;
60       class DataInputStream;
61       class DataOutput;
62       class DataOutputStream;
63       class DeleteFileHelper;
64       class DeleteFileHelper$1;
65       class EOFException;
66       class Externalizable;
67       class File;
68       class FileDescriptor;
69       class FileFilter;
70       class FileInputStream;
71       class FileNotFoundException;
72       class FileOutputStream;
73       class FilePermission;
74       class FileReader;
75       class FileWriter;
76       class FilenameFilter;
77       class FilterInputStream;
78       class FilterOutputStream;
79       class FilterReader;
80       class FilterWriter;
81       class Flushable;
82       class IOException;
83       class InputStream;
84       class InputStreamReader;
85       class InterruptedIOException;
86       class InvalidClassException;
87       class InvalidObjectException;
88       class LineNumberInputStream;
89       class LineNumberReader;
90       class NotActiveException;
91       class NotSerializableException;
92       class ObjectInput;
93       class ObjectInputStream;
94       class ObjectInputStream$1;
95       class ObjectInputStream$2;
96       class ObjectInputStream$GetField;
97       class ObjectInputStream$ValidatorAndPriority;
98       class ObjectInputValidation;
99       class ObjectOutput;
100       class ObjectOutputStream;
101       class ObjectOutputStream$1;
102       class ObjectOutputStream$PutField;
103       class ObjectStreamClass;
104       class ObjectStreamClass$1;
105       class ObjectStreamClass$2;
106       class ObjectStreamClass$InterfaceComparator;
107       class ObjectStreamClass$MemberComparator;
108       class ObjectStreamConstants;
109       class ObjectStreamException;
110       class ObjectStreamField;
111       class ObjectStreamField$1;
112       class OptionalDataException;
113       class OutputStream;
114       class OutputStreamWriter;
115       class PipedInputStream;
116       class PipedOutputStream;
117       class PipedReader;
118       class PipedWriter;
119       class PrintStream;
120       class PrintWriter;
121       class PushbackInputStream;
122       class PushbackReader;
123       class RandomAccessFile;
124       class Reader;
125       class SequenceInputStream;
126       class Serializable;
127       class SerializablePermission;
128       class StreamCorruptedException;
129       class StreamTokenizer;
130       class StringBufferInputStream;
131       class StringReader;
132       class StringWriter;
133       class SyncFailedException;
134       class UTFDataFormatException;
135       class UnsupportedEncodingException;
136       class VMObjectStreamClass;
137       class WriteAbortedException;
138       class Writer;
139     }
140
141     namespace lang
142     {
143       class AbstractMethodError;
144       class Appendable;
145       class ArithmeticException;
146       class ArrayIndexOutOfBoundsException;
147       class ArrayStoreException;
148       class AssertionError;
149       class Boolean;
150       class Byte;
151       class CharSequence;
152       class Character;
153       class Character$Subset;
154       class Character$UnicodeBlock;
155       class Class;
156       class ClassCastException;
157       class ClassCircularityError;
158       class ClassFormatError;
159       class ClassLoader;
160       class ClassNotFoundException;
161       class CloneNotSupportedException;
162       class Cloneable;
163       class Comparable;
164       class Compiler;
165       class ConcreteProcess;
166       class ConcreteProcess$EOFInputStream;
167       class ConcreteProcess$ProcessManager;
168       class Double;
169       class Enum;
170       class EnumConstantNotPresentException;
171       class Error;
172       class Exception;
173       class ExceptionInInitializerError;
174       class Float;
175       class IllegalAccessError;
176       class IllegalAccessException;
177       class IllegalArgumentException;
178       class IllegalMonitorStateException;
179       class IllegalStateException;
180       class IllegalThreadStateException;
181       class IncompatibleClassChangeError;
182       class IndexOutOfBoundsException;
183       class InheritableThreadLocal;
184       class InstantiationError;
185       class InstantiationException;
186       class Integer;
187       class InternalError;
188       class InterruptedException;
189       class Iterable;
190       class LinkageError;
191       class Long;
192       class Math;
193       class NegativeArraySizeException;
194       class NoClassDefFoundError;
195       class NoSuchFieldError;
196       class NoSuchFieldException;
197       class NoSuchMethodError;
198       class NoSuchMethodException;
199       class NullPointerException;
200       class Number;
201       class NumberFormatException;
202       class Object;
203       class OutOfMemoryError;
204       class Package;
205       class Process;
206       class Readable;
207       class Runnable;
208       class Runtime;
209       class RuntimeException;
210       class RuntimePermission;
211       class SecurityContext;
212       class SecurityException;
213       class SecurityManager;
214       class Short;
215       class StackOverflowError;
216       class StackTraceElement;
217       class StrictMath;
218       class String;
219       class String$CaseInsensitiveComparator;
220       class StringBuffer;
221       class StringBuilder;
222       class StringIndexOutOfBoundsException;
223       class System;
224       class Thread;
225       class Thread$UncaughtExceptionHandler;
226       class ThreadDeath;
227       class ThreadGroup;
228       class ThreadLocal;
229       class Throwable;
230       class Throwable$StaticData;
231       class TypeNotPresentException;
232       class UnknownError;
233       class UnsatisfiedLinkError;
234       class UnsupportedClassVersionError;
235       class UnsupportedOperationException;
236       class VMClassLoader;
237       class VMCompiler;
238       class VMDouble;
239       class VMFloat;
240       class VMSecurityManager;
241       class VMThrowable;
242       class VerifyError;
243       class VirtualMachineError;
244       class Void;
245       namespace annotation
246       {
247         class Annotation;
248         class AnnotationFormatError;
249         class AnnotationTypeMismatchException;
250       }
251
252       namespace instrument
253       {
254         class ClassDefinition;
255         class ClassFileTransformer;
256         class IllegalClassFormatException;
257         class Instrumentation;
258         class UnmodifiableClassException;
259       }
260
261       namespace ref
262       {
263         class PhantomReference;
264         class Reference;
265         class ReferenceQueue;
266         class SoftReference;
267         class WeakReference;
268       }
269
270       namespace reflect
271       {
272         class AccessibleObject;
273         class AnnotatedElement;
274         class Array;
275         class Constructor;
276         class Field;
277         class GenericArrayType;
278         class GenericDeclaration;
279         class GenericSignatureFormatError;
280         class InvocationHandler;
281         class InvocationTargetException;
282         class MalformedParameterizedTypeException;
283         class Member;
284         class Method;
285         class Modifier;
286         class ParameterizedType;
287         class Proxy;
288         class Proxy$ClassFactory;
289         class Proxy$ProxyData;
290         class Proxy$ProxySignature;
291         class Proxy$ProxyType;
292         class ReflectPermission;
293         class Type;
294         class TypeVariable;
295         class UndeclaredThrowableException;
296         class VMProxy;
297         class WildcardType;
298       }
299     }
300
301     namespace util
302     {
303       class AbstractCollection;
304       class AbstractList;
305       class AbstractList$1;
306       class AbstractList$2;
307       class AbstractList$RandomAccessSubList;
308       class AbstractList$SubList;
309       class AbstractList$SubList$3;
310       class AbstractMap;
311       class AbstractMap$1;
312       class AbstractMap$1$2;
313       class AbstractMap$3;
314       class AbstractMap$3$4;
315       class AbstractMap$BasicMapEntry;
316       class AbstractSequentialList;
317       class AbstractSet;
318       class ArrayList;
319       class Arrays;
320       class Arrays$ArrayList;
321       class BitSet;
322       class Calendar;
323       class Collection;
324       class Collections;
325       class Collections$1;
326       class Collections$CopiesList;
327       class Collections$EmptyList;
328       class Collections$EmptyMap;
329       class Collections$EmptySet;
330       class Collections$ReverseComparator;
331       class Collections$SingletonList;
332       class Collections$SingletonMap;
333       class Collections$SingletonMap$3;
334       class Collections$SingletonSet;
335       class Collections$SingletonSet$2;
336       class Collections$SynchronizedCollection;
337       class Collections$SynchronizedIterator;
338       class Collections$SynchronizedList;
339       class Collections$SynchronizedListIterator;
340       class Collections$SynchronizedMap;
341       class Collections$SynchronizedMap$4$SynchronizedMapEntry;
342       class Collections$SynchronizedMap$5;
343       class Collections$SynchronizedMap$5$6;
344       class Collections$SynchronizedRandomAccessList;
345       class Collections$SynchronizedSet;
346       class Collections$SynchronizedSortedMap;
347       class Collections$SynchronizedSortedSet;
348       class Collections$UnmodifiableCollection;
349       class Collections$UnmodifiableIterator;
350       class Collections$UnmodifiableList;
351       class Collections$UnmodifiableListIterator;
352       class Collections$UnmodifiableMap;
353       class Collections$UnmodifiableMap$UnmodifiableEntrySet;
354       class Collections$UnmodifiableMap$UnmodifiableEntrySet$7;
355       class Collections$UnmodifiableMap$UnmodifiableEntrySet$7$8;
356       class Collections$UnmodifiableRandomAccessList;
357       class Collections$UnmodifiableSet;
358       class Collections$UnmodifiableSortedMap;
359       class Collections$UnmodifiableSortedSet;
360       class Comparator;
361       class ConcurrentModificationException;
362       class Currency;
363       class Date;
364       class Dictionary;
365       class EmptyStackException;
366       class Enumeration;
367       class EventListener;
368       class EventListenerProxy;
369       class EventObject;
370       class GregorianCalendar;
371       class HashMap;
372       class HashMap$1;
373       class HashMap$2;
374       class HashMap$3;
375       class HashMap$HashEntry;
376       class HashMap$HashIterator;
377       class HashSet;
378       class Hashtable;
379       class Hashtable$1;
380       class Hashtable$2;
381       class Hashtable$3;
382       class Hashtable$EntryEnumerator;
383       class Hashtable$EntryIterator;
384       class Hashtable$HashEntry;
385       class Hashtable$KeyEnumerator;
386       class Hashtable$KeyIterator;
387       class Hashtable$ValueEnumerator;
388       class Hashtable$ValueIterator;
389       class IdentityHashMap;
390       class IdentityHashMap$1;
391       class IdentityHashMap$2;
392       class IdentityHashMap$3;
393       class IdentityHashMap$IdentityEntry;
394       class IdentityHashMap$IdentityIterator;
395       class InvalidPropertiesFormatException;
396       class Iterator;
397       class LinkedHashMap;
398       class LinkedHashMap$1;
399       class LinkedHashMap$LinkedHashEntry;
400       class LinkedHashSet;
401       class LinkedList;
402       class LinkedList$Entry;
403       class LinkedList$LinkedListItr;
404       class List;
405       class ListIterator;
406       class ListResourceBundle;
407       class Locale;
408       class Map;
409       class Map$Entry;
410       class MissingResourceException;
411       class NoSuchElementException;
412       class Observable;
413       class Observer;
414       class Properties;
415       class PropertyPermission;
416       class PropertyPermissionCollection;
417       class PropertyResourceBundle;
418       class Random;
419       class RandomAccess;
420       class ResourceBundle;
421       class ResourceBundle$BundleKey;
422       class Set;
423       class SimpleTimeZone;
424       class SortedMap;
425       class SortedSet;
426       class Stack;
427       class StringTokenizer;
428       class TimeZone;
429       class TimeZone$1;
430       class Timer;
431       class Timer$Scheduler;
432       class Timer$TaskQueue;
433       class TimerTask;
434       class TooManyListenersException;
435       class TreeMap;
436       class TreeMap$1;
437       class TreeMap$2;
438       class TreeMap$3;
439       class TreeMap$Node;
440       class TreeMap$SubMap;
441       class TreeMap$SubMap$4;
442       class TreeMap$SubMap$5;
443       class TreeMap$SubMap$6;
444       class TreeMap$TreeIterator;
445       class TreeSet;
446       class VMTimeZone;
447       class Vector;
448       class Vector$1;
449       class WeakHashMap;
450       class WeakHashMap$1;
451       class WeakHashMap$WeakBucket;
452       class WeakHashMap$WeakBucket$WeakEntry;
453       class WeakHashMap$WeakEntrySet;
454       class WeakHashMap$WeakEntrySet$2;
455       namespace jar
456       {
457         class Attributes;
458         class Attributes$Name;
459         class JarEntry;
460         class JarException;
461         class JarFile;
462         class JarFile$EntryInputStream;
463         class JarFile$JarEnumeration;
464         class JarInputStream;
465         class JarOutputStream;
466         class Manifest;
467       }
468
469       namespace logging
470       {
471         class ConsoleHandler;
472         class ErrorManager;
473         class FileHandler;
474         class FileHandler$ostr;
475         class Filter;
476         class Formatter;
477         class Handler;
478         class Level;
479         class LogManager;
480         class LogRecord;
481         class Logger;
482         class Logger$1;
483         class LoggingPermission;
484         class MemoryHandler;
485         class SimpleFormatter;
486         class SocketHandler;
487         class StreamHandler;
488         class XMLFormatter;
489       }
490
491       namespace prefs
492       {
493         class AbstractPreferences;
494         class AbstractPreferences$1;
495         class AbstractPreferences$2;
496         class BackingStoreException;
497         class InvalidPreferencesFormatException;
498         class NodeChangeEvent;
499         class NodeChangeListener;
500         class PreferenceChangeEvent;
501         class PreferenceChangeListener;
502         class Preferences;
503         class Preferences$1;
504         class PreferencesFactory;
505       }
506
507       namespace regex
508       {
509         class MatchResult;
510         class Matcher;
511         class Pattern;
512         class PatternSyntaxException;
513       }
514
515       namespace zip
516       {
517         class Adler32;
518         class CRC32;
519         class CheckedInputStream;
520         class CheckedOutputStream;
521         class Checksum;
522         class DataFormatException;
523         class Deflater;
524         class DeflaterOutputStream;
525         class GZIPInputStream;
526         class GZIPOutputStream;
527         class Inflater;
528         class InflaterInputStream;
529         class ZipConstants;
530         class ZipEntry;
531         class ZipException;
532         class ZipFile;
533         class ZipFile$1;
534         class ZipFile$PartialInputStream;
535         class ZipFile$ZipEntryEnumeration;
536         class ZipInputStream;
537         class ZipOutputStream;
538       }
539     }
540   }
541 }
542   
543 typedef struct java::lang::Object* jobject;
544 typedef class java::lang::Class* jclass;
545 typedef class java::lang::Throwable* jthrowable;
546 typedef class java::lang::String* jstring;
547 struct _Jv_JNIEnv;
548
549 typedef struct _Jv_Field *jfieldID;
550 typedef struct _Jv_Method *jmethodID;
551
552 extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__));
553 extern "C" jobject _Jv_AllocObjectNoFinalizer (jclass) __attribute__((__malloc__));
554 extern "C" jobject _Jv_AllocObjectNoInitNoFinalizer (jclass) __attribute__((__malloc__));
555 #ifdef JV_HASH_SYNCHRONIZATION
556   extern "C" jobject _Jv_AllocPtrFreeObject (jclass)
557                             __attribute__((__malloc__));
558 #else
559   // Collector still needs to scan sync_info
560   static inline jobject _Jv_AllocPtrFreeObject (jclass klass)
561   {
562     return _Jv_AllocObject(klass);
563   }
564 #endif
565 extern "C" jboolean _Jv_IsInstanceOf(jobject, jclass);
566 extern "C" jstring _Jv_AllocString(jsize) __attribute__((__malloc__));
567 extern "C" jstring _Jv_NewString (const jchar*, jsize)
568   __attribute__((__malloc__));
569 extern jint _Jv_FormatInt (jchar* bufend, jint num);
570 extern "C" jchar* _Jv_GetStringChars (jstring str);
571 extern "C" void _Jv_MonitorEnter (jobject);
572 extern "C" void _Jv_MonitorExit (jobject);
573 extern "C" jstring _Jv_NewStringUTF (const char *bytes)
574   __attribute__((__malloc__));
575 extern "C" jstring _Jv_NewStringLatin1(const char*, jsize)
576   __attribute__((__malloc__));
577 extern "C" jsize _Jv_GetStringUTFLength (jstring);
578 extern "C" jsize _Jv_GetStringUTFRegion (jstring, jsize, jsize, char *);
579 extern "C" jint _Jv_hashUtf8String (const char*, int);
580
581 struct _Jv_VMOption
582 {
583   // a VM initialization option
584   char* optionString;
585   // extra information associated with this option
586   void* extraInfo;
587 };
588
589 struct _Jv_VMInitArgs
590 {
591   // for compatibility with JavaVMInitArgs
592   jint version;
593
594   // number of VM initialization options
595   jint nOptions;
596
597   // an array of VM initialization options
598   struct _Jv_VMOption* options;
599
600   // true if the option parser should ignore unrecognized options
601   jboolean ignoreUnrecognized;
602 };
603
604 extern jint _Jv_CreateJavaVM (struct _Jv_VMInitArgs*);
605
606 void
607 _Jv_ThreadRun (java::lang::Thread* thread);
608 jint
609 _Jv_AttachCurrentThread(java::lang::Thread* thread);
610 extern "C" java::lang::Thread*
611 _Jv_AttachCurrentThread(jstring name, java::lang::ThreadGroup* group);
612 extern "C" java::lang::Thread*
613 _Jv_AttachCurrentThreadAsDaemon(jstring name, java::lang::ThreadGroup* group);
614 extern "C" jint _Jv_DetachCurrentThread (void);
615
616 extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__));
617 extern "C" void* _Jv_Malloc (jsize) __attribute__((__malloc__));
618 extern "C" void* _Jv_Realloc (void *, jsize);
619 extern "C" void _Jv_Free (void*);
620 extern void (*_Jv_RegisterClassHook) (jclass cl);
621 extern "C" void _Jv_RegisterClassHookDefault (jclass);
622
623 typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__)));
624 typedef unsigned int _Jv_uint __attribute__((__mode__(__SI__)));
625 typedef unsigned int _Jv_ulong __attribute__((__mode__(__DI__)));
626
627 class _Jv_Utf8Const
628 {
629   _Jv_ushort hash;
630   _Jv_ushort length;    /* In bytes, of data portion, without final '\0'. */
631   char data[1];         /* In Utf8 format, with final '\0'. */
632  public:
633   /** Return same value of java.lang.String's hashCode. */
634   jint hash32() { return _Jv_hashUtf8String(data, length); }
635   /** Return a hash code that has at least 16 bits of information. */
636   _Jv_ushort hash16 () { return hash; }
637   /** Return a hash code that has at least 8 bits of information. */
638   _Jv_ushort hash8 () { return hash; }
639   /** Length in bytes of the UTF8-encoding. */
640   _Jv_ushort len () const { return length; }
641   /** Pointer to the first byte in the NUL-terminated UTF8-encoding. */
642   char* chars() { return data; }
643   /** Pointer to the NUL byte that terminated the UTF8-encoding. */
644   char* limit() { return data+length; }
645   /** Return the first byte in the UTF8-encoding. */
646   char first() const { return data[0]; }
647   /** Create a (non-interned) java.lang.String from this UTF8Const. */
648   jstring toString() { return _Jv_NewStringUTF(data); }
649   /** Given an UTF8 string, how many bytes needed for a UTF8Const,
650       including struct header, and final NUL.  I.e. what to pas to malloc. */
651   static int space_needed (const char *, int len)
652   { return sizeof (_Jv_Utf8Const) + len + 1; }
653   /** Given an allocated _Jv_Utf8Const, copy / fill it in. */
654   void init (const char *s, int len);
655   friend jboolean _Jv_equalUtf8Consts (const _Jv_Utf8Const*, const _Jv_Utf8Const *);
656   friend jboolean _Jv_equal (_Jv_Utf8Const*, jstring, jint);
657   friend jboolean _Jv_equaln (_Jv_Utf8Const*, jstring, jint);
658   friend jboolean _Jv_equalUtf8Classnames (const _Jv_Utf8Const*,
659                                              const _Jv_Utf8Const*);
660   friend jboolean _Jv_isPrimitiveOrDerived (const _Jv_Utf8Const*);
661   friend _Jv_Utf8Const *_Jv_makeUtf8Const (const char*, int);
662   friend _Jv_Utf8Const *_Jv_makeUtf8Const (jstring);
663   friend jstring _Jv_NewStringUtf8Const (_Jv_Utf8Const*);
664 };
665
666
667 #endif /* __JAVAPRIMS_H__ */