1 /*
2 * @(#)oobj.h 1.5 00/04/12
3 *
4 * Copyright 1995-1998 by Sun Microsystems, Inc.,
5 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
6 * All rights reserved.
7 *
8 * This software is the confidential and proprietary information
9 * of Sun Microsystems, Inc. ("Confidential Information"). You
10 * shall not disclose such Confidential Information and shall use
11 * it only in accordance with the terms of the license agreement
12 * you entered into with Sun.
13 * Use is subject to license terms.
14 */
15 /*
16 * Java object header format
17 */
19 #ifndef _OOBJ_H_
20 #define _OOBJ_H_
22 #include <stddef.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <limits.h>
32 #define JAVA_CLASSFILE_MAGIC 0xCafeBabe
35 #define JAVASRCEXTLEN 4
37 #define JAVAOBJEXTLEN 5
39 #define JAVA_VERSION 45
40 #define JAVA_MINOR_VERSION 3
41 #define ARRAYHEADER long alloclen
43 /* The size (in bytes) of a statically allocated area that the
44 * verifier uses internally in various string operations.
45 */
46 #ifndef STRINGBUFFERSIZE
47 #define STRINGBUFFERSIZE 512
48 #endif
52 /* maximum size allowed for package name of a class file */
53 #define MAXPACKAGENAME 1024
55 #define MAXPATHLEN 255
57 #define HandleTo(T) typedef struct H##T { Class##T *obj; struct methodtable *methods;} H##T
72 #define ALIGN(n) (((n)+3)&~3)
73 #define UCALIGN(n) ((unsigned char *)ALIGN((int)(n)))
92 OBJECT static_value;
97 };
99 #define fieldname(fb) ((fb)->name)
100 #define fieldsig(fb) ((fb)->signature)
101 #define fieldIsArray(fb) (fieldsig(fb)[0] == SIGNATURE_ARRAY)
102 #define fieldIsClass(fb) (fieldsig(fb)[0] == SIGNATURE_CLASS)
103 #define fieldclass(fb) ((fb)->clazz)
107 #define VERIFIER_TOOL
109 /* Includes/eliminates a large amount of optional debugging code
110 * (such as class and stack frame printing operations) in/from
111 * the system. By eliminating debug code, the system will be smaller.
112 * Inclusion of debugging code increases the size of the system but
113 * does not introduce any performance overhead unless calls to the
114 * debugging routines are added to the source code or various tracing
115 * options are turned on.
116 */
118 #ifndef INCLUDEDEBUGCODE
119 #define INCLUDEDEBUGCODE 0
120 #endif
122 #define DEBUG_VERIFIER 1
123 #define DEBUG_READFROMFILE 0
126 ITEM_Bogus,
128 ITEM_Integer,
129 ITEM_Float,
130 ITEM_Double,
132 ITEM_Long,
135 to super() */
139 /* The following three are only used within array types.
140 * Normally, we use ITEM_Integer, instead. */
141 ITEM_Boolean,
142 ITEM_Byte,
143 ITEM_Short,
144 ITEM_Char
145 };
147 /* These are the constants that appear in class files. */
149 CF_ITEM_Bogus,
150 CF_ITEM_Integer,
151 CF_ITEM_Float,
152 CF_ITEM_Double,
153 CF_ITEM_Long,
154 CF_ITEM_Null,
155 CF_ITEM_InitObject,
157 CF_ITEM_Object,
158 CF_ITEM_NewObject,
159 };
164 };
172 };
191 /* 2 spare bytes here */
201 };
208 };
216 };
281 /* Note: any handles in this structure must also have explicit
282 code in the ScanClasses() routine of the garbage collector
283 to mark the handle. */
285 /* Things following here are saved in the .class file */
355 };
362 };
367 #define cbAccess(cb) ((unhand(cb))->access)
368 #define cbClassname(cb) ((unhand(cb))->classname)
369 #define cbConstantPool(cb) ((unhand(cb))->constantpool)
370 #define cbConstantPoolCount(cb) ((unhand(cb))->constantpool_count)
371 #define cbFields(cb) ((unhand(cb))->fields)
372 #define cbFieldsCount(cb) ((unhand(cb))->fields_count)
373 #define cbFinalizer(cb) ((unhand(cb))->finalizer)
374 #define cbFlags(cb) ((unhand(cb))->flags)
375 #define cbHandle(cb) (cb)
376 #define cbImplements(cb) ((unhand(cb))->implements)
377 #define cbImplementsCount(cb) ((unhand(cb))->implements_count)
378 #define cbInstanceSize(cb) ((unhand(cb))->instance_size)
379 #define cbIntfMethodTable(cb) ((unhand(cb))->imethodtable)
380 #define cbLastSubclassOf(cb) ((unhand(cb))->last_subclass_of)
381 #define cbLoader(cb) ((unhand(cb))->loader)
382 #define cbMajorVersion(cb) ((unhand(cb))->major_version)
383 #define cbMethods(cb) ((unhand(cb))->methods)
384 #define cbMethodsCount(cb) ((unhand(cb))->methods_count)
385 #define cbMethodTable(cb) ((unhand(cb))->methodtable)
386 #define cbMethodTableMem(cb) ((unhand(cb))->methodtable_mem)
387 #define cbMethodTableSize(cb) ((unhand(cb))->methodtable_size)
388 #define cbMinorVersion(cb) ((unhand(cb))->minor_version)
389 #define cbName(cb) ((unhand(cb))->name)
390 #define cbSigners(cb) ((unhand(cb))->signers)
391 #define cbSlotTable(cb) ((unhand(cb))->slottable)
392 #define cbSlotTableSize(cb) ((unhand(cb))->slottbl_size)
393 #define cbSourceName(cb) ((unhand(cb))->source_name)
394 #define cbSuperclass(cb) ((unhand(cb))->superclass)
395 #define cbSuperName(cb) ((unhand(cb))->super_name)
396 #define cbThisHash(cb) ((unhand(cb))->hashinfo.cbhash.thishash)
397 #define cbTotalHash(cb) ((unhand(cb))->hashinfo.cbhash.totalhash)
398 #define cbInitThread(cb) ((unhand(cb))->init_thread)
399 #define cbInnerClasses(cb) ((unhand(cb))->inner_classes)
400 #define cbInnerClassesCount(cb)((unhand(cb))->inner_classes_count)
404 #define cbAbsoluteSourceName(cb) ((unhand(cb))->absolute_source_name)
405 #define cbTimestamp(cb) ((unhand(cb))->timestamp)
407 #define cbIsInterface(cb) ((cbAccess(cb) & ACC_INTERFACE) != 0)
408 #define cbIsAbstract(cb) ((cbAccess(cb) & ACC_ABSTRACT) != 0)
409 #define cbAccessNotAbstract(cb) ((unhand(cb))->access & ~ACC_ABSTRACT)
411 /* These are currently only valid for primitive types */
412 #define cbIsPrimitive(cb) (CCIs(cb, Primitive))
413 #define cbTypeCode(cb) ((unhand(cb))->hashinfo.cbtypeinfo.typecode)
414 #define cbTypeSig(cb) ((unhand(cb))->hashinfo.cbtypeinfo.typesig)
415 #define cbSlotSize(cb) ((unhand(cb))->hashinfo.cbtypeinfo.slotsize)
416 #define cbElementSize(cb) ((unhand(cb))->hashinfo.cbtypeinfo.elementsize)
420 #define twoword_static_address(fb) ((fb)->u.static_address)
421 #define normal_static_address(fb) (&(fb)->u.static_value)
423 /* ClassClass flags */
436 #define CCIs(cb,flag) (((unhand(cb))->flags & CCF_Is##flag) != 0)
437 #define CCSet(cb,flag) ((unhand(cb))->flags |= CCF_Is##flag)
438 #define CCClear(cb,flag) ((unhand(cb))->flags &= ~CCF_Is##flag)
440 /* map from pc to line number */
443 line_number;
444 };
449 /* Symbol table entry for local variables and parameters.
450 pc0/length defines the range that the variable is valid, slot
451 is the position in the local variable array in ExecEnv.
452 nameoff and sigoff are offsets into the string table for the
453 variable name and type signature. A variable is defined with
454 DefineVariable, and at that time, the node for that name is
455 stored in the localvar entry. When code generate is completed
456 for a particular scope, a second pass it made to replace the
457 src node entry with the correct length. */
465 };
467 /* Try/catch is implemented as follows. On a per class basis,
468 there is a catch frame handler (below) for each catch frame
469 that appears in the source. It contains the pc range of the
470 corresponding try body, a pc to jump to in the event that that
471 handler is chosen, and a catchType which must match the object
472 being thrown if that catch handler is to be taken.
474 The list of catch frames are sorted by pc. If one range is
475 inside another, then outer most range (the one that encompasses
476 the other) appears last in the list. Therefore, it is possible
477 to search forward, and the first one that matches is the
478 innermost one.
480 Methods with catch handlers will layout the code without the
481 catch frames. After all the code is generated, the catch
482 clauses are generated and table entries are created.
484 When the class is complete, the table entries are dumped along
485 with the rest of the class. */
492 };
494 #define MC_SUPER (1<<5)
495 #define MC_NARGSMASK (MC_SUPER-1)
496 #define MC_INT (0<<6)
497 #define MC_FLOAT (1<<6)
498 #define MC_VOID (2<<6)
499 #define MC_OTHER (3<<6)
500 #define MC_TYPEMASK (3<<6)
505 CONSTANT_Integer,
506 CONSTANT_Float,
507 CONSTANT_Long,
508 CONSTANT_Double,
509 CONSTANT_Class,
510 CONSTANT_String,
511 CONSTANT_Fieldref,
512 CONSTANT_Methodref,
513 CONSTANT_InterfaceMethodref,
514 CONSTANT_NameAndType
515 };
527 };
531 #define CONSTANT_POOL_ENTRY_RESOLVED 0x80
532 #define CONSTANT_POOL_ENTRY_TYPEMASK 0x7F
533 #define CONSTANT_POOL_TYPE_TABLE_GET(cp,i) (((unsigned char *)(cp))[i])
534 #define CONSTANT_POOL_TYPE_TABLE_PUT(cp,i,v) (CONSTANT_POOL_TYPE_TABLE_GET(cp,i) = (v))
535 #define CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(cp,i) \
536 (CONSTANT_POOL_TYPE_TABLE_GET(cp,i) |= CONSTANT_POOL_ENTRY_RESOLVED)
537 #define CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(cp,i) \
538 ((CONSTANT_POOL_TYPE_TABLE_GET(cp,i) & CONSTANT_POOL_ENTRY_RESOLVED) != 0)
539 #define CONSTANT_POOL_TYPE_TABLE_GET_TYPE(cp,i) \
540 (CONSTANT_POOL_TYPE_TABLE_GET(cp,i) & CONSTANT_POOL_ENTRY_TYPEMASK)
542 #define CONSTANT_POOL_TYPE_TABLE_INDEX 0
543 #define CONSTANT_POOL_UNUSED_INDEX 1
545 /* The following are used by the constant pool of "array" classes. */
547 #define CONSTANT_POOL_ARRAY_DEPTH_INDEX 1
548 #define CONSTANT_POOL_ARRAY_TYPE_INDEX 2
549 #define CONSTANT_POOL_ARRAY_CLASS_INDEX 3
550 #define CONSTANT_POOL_ARRAY_LENGTH 4
552 /*
553 * Package shorthand: this isn't obviously the correct place.
554 */
559 #define unhand(o) ((o)->obj)
606 //bool_t IsLegalClassname(char *name, bool_t allowArrayClass);
610 /* Detecting class circularities */
616 /* error message occurred during class loading */
618 };
640 #define BINCLASS_LOCK()
641 #define BINCLASS_UNLOCK()
642 #define LOADCLASS_LOCK()
643 #define LOADCLASS_UNLOCK()
644 #define NAMETYPEHASH_LOCK()
645 #define NAMETYPEHASH_UNLOCK()
654 #define METHOD_FLAG_BITS 5
657 #define LENGTH_MASK METHOD_MASK
659 #define mt_slot(methodtable, slot) (methodtable)->methods[slot]
661 #define monitorEnter(m)
662 #define monitorExit(m)
664 #define exceptionOccurred(ee) 0
679 /* Set to 1 if any errors encountered
680 * during class verification in VerifyFile()
681 */