Manipulation of attributes is performed in cfattrib.c. All other work is done here.
The JVM specification is available from Sun Microsystems' web site at http://java.sun.com/docs/books/vmspec/index.html and may be read online at http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html
The Java 5 class file format is available as a PDF file separately at http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat-final-draft.pdf and was the basis for the ClassFile structure of this implementation.
Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Definition in file classfile.c.
#include "arch.h"
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include "jvmcfg.h"
#include "cfmacros.h"
#include "classfile.h"
#include "classpath.h"
#include "exit.h"
#include "jvm.h"
#include "native.h"
#include "util.h"
Go to the source code of this file.
Range check of constant_pool indices. | |||||||||||||
Range check constant_pool cpidx against max index, with/without typed pointer.
(Testing
| |||||||||||||
#define | CPIDX_RANGE_CHECK(pcfs, cpidx, msg) | ||||||||||||
Range check a simple index against the constant_pool_count value. | |||||||||||||
#define | CPTYPEIDX_RANGE_CHECK(type, pcfs, cpidx, msg) | ||||||||||||
Range check a typed pointer against the constant_pool_count value. | |||||||||||||
Read Java object code (class data) from disk files. | |||||||||||||
| |||||||||||||
u1 * | classfile_readclassfile (rchar *filename) | ||||||||||||
Read a JVM class file. | |||||||||||||
u1 * | classfile_readjarfile (rchar *filename) | ||||||||||||
Read an entire JAR file into temporary disk area and load up one class file from it. | |||||||||||||
Defines | |||||||||||||
#define | ALLOC_CF_ITEM(spec_typedef, pbytes, pcfsi, binding_struct) | ||||||||||||
Allocate either a field_info or method_info structure. | |||||||||||||
#define | ALLOC_CP_INFO(spec_typedef, binding_struct) | ||||||||||||
Allocate a cp_info_dup structure containing any generic type of constant_pool entry. | |||||||||||||
#define | READ_SYSCALL_FAILURE(expr, msg) | ||||||||||||
Report an error rnull pointer if a system call fails. | |||||||||||||
Functions | |||||||||||||
ClassFile * | classfile_allocate_primative (jvm_basetype basetype) | ||||||||||||
Build up empty JVM class file structure for use by Java primative data types. | |||||||||||||
static void | classfile_c_dummy (void) | ||||||||||||
ClassFile * | classfile_loadclassdata (u1 *pclassfile_image) | ||||||||||||
Parse an in-memory JVM class file, create structures to point to various parts of it, per JVM spec pseuco-code structures. | |||||||||||||
rvoid | classfile_unloadclassdata (ClassFile *pcfs) | ||||||||||||
Release all heap allocated to a fully loaded ClassFile structure. | |||||||||||||
Variables | |||||||||||||
static char * | classfile_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/classfile.c $ $Id: classfile.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." |
|
Value: misc_adj = sizeof(u1) * CP_INFO_NUM_EMPTIES; \ \ cf_item_size = sizeof(spec_typedef)-sizeof(struct binding_struct); \ pcpd = HEAP_GET_METHOD(misc_adj + sizeof(spec_typedef), rfalse); \ memcpy(((rbyte *) pcpd) + misc_adj,pcpbytes,cf_item_size); \ \ pcpd->empty[0] = FILL_INFO_DUP0; \ pcpd->empty[1] = FILL_INFO_DUP1; \ pcpd->empty[2] = FILL_INFO_DUP2; Allocate space from heap, populate from class file data, and fill in initial pad bytes.
Definition at line 216 of file classfile.c. Referenced by classfile_loadclassdata(). |
|
Value: cf_item_size = sizeof(spec_typedef) - \ sizeof(struct binding_struct) - \ sizeof(attribute_info_dup **); \ pcfsi = HEAP_GET_METHOD(sizeof(spec_typedef), rfalse); \ memcpy(((rbyte *) pcfsi),pbytes,cf_item_size); Allocate space from heap and populate from class file data,
Definition at line 252 of file classfile.c. Referenced by classfile_loadclassdata(). |
|
Value: LOAD_SYSCALL_FAILURE(( /* ((((type *) &pcpd->cp)->cpidx) < 0) || */\ ((((type *) &pcpd->cp)->cpidx) >= \ pcfs->constant_pool_count)), \ msg, \ rnull, \ rnull);
Definition at line 290 of file classfile.c. Referenced by classfile_loadclassdata(). |
|
Value: LOAD_SYSCALL_FAILURE((/* (cpidx < 0) || */ \ (cpidx >= pcfs->constant_pool_count)), \ msg, \ rnull, \ rnull);
Definition at line 303 of file classfile.c. Referenced by classfile_loadclassdata(). |
|
Value: GENERIC_FAILURE_PTR((expr), \ DMLMIN, \ "classfile_readclassfile", \ msg, \ rvoid, \ rnull, \ rnull)
Definition at line 1666 of file classfile.c. |
|
Definition at line 63 of file classfile.c. |
|
Build up empty JVM class file structure for use by Java primative data types. Each primative data type needs a minimal class definition to avoid having special cases for class processing logic. Also, treating primatives like classes can provide convenient information on data size types, like (jlong) versus (jint). This can be provided by the base type information, which is passed in here when creating these minimal classes. The constant pool for such a minima class looks like this:
For internal use only. INITIALIZE TO ZEROES all fields so there are automatic rnull pointers in case of failure along the way. < Magic number for class files
Since
< Declared
Definition at line 121 of file classfile.c. References ACC_SYNTHETIC, ClassFile::access_flags, ClassFile::attributes, ClassFile::attributes_count, CONSTANT_Utf8_info::bytes, CLASSFILE_MAGIC, CONSTANT_Class, ClassFile::constant_pool, ClassFile::constant_pool_count, CONSTANT_Utf8, ClassFile::fields, ClassFile::fields_count, HEAP_GET_DATA, ClassFile::interfaces, ClassFile::interfaces_count, CONSTANT_Utf8_info::length, ClassFile::magic, ClassFile::major_version, ClassFile::methods, ClassFile::methods_count, ClassFile::minor_version, CONSTANT_Class_info::name_index, PTR_THIS_CP_Class, PTR_THIS_CP_Utf8, rfalse, rnull, rtrue, ClassFile::super_class, CONSTANT_Utf8_info::tag, CONSTANT_Class_info::tag, ClassFile::this_class, VERSION_MAJOR_JDK2, and VERSION_MINOR_DEFAULT. |
|
Parse an in-memory JVM class file, create structures to point to various parts of it, per JVM spec pseuco-code structures. Interpret the class file data and load up the data structures which access it, such as the fully qualified class names, the code area, etc.
< Magic number for class files < Magic number for class files < Convenient alias for DML1 < Convenient alias for DML5 < Convenient alias for DML5 < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML1
< References < Ref first constant item < Size of padding for cp_info structures insize of cp_info_dup structure < Convenient alias for DML1 < Size of padding for cp_info structures insize of cp_info_dup structure < Convenient alias for DML1
< Invalid basetype due to malformed < Size of padding for cp_info structures insize of cp_info_dup structure < Convenient alias for DML1 < Convenient alias for DML1 < Size of padding for cp_info structures insize of cp_info_dup structure < Convenient alias for DML1 < Convenient alias for DML1 < Size of padding for cp_info structures insize of cp_info_dup structure < Convenient alias for DML1 < Size of padding for cp_info structures insize of cp_info_dup structure < Size of padding for cp_info structures insize of cp_info_dup structure < Size of padding for cp_info structures insize of cp_info_dup structure < Size of padding for cp_info structures insize of cp_info_dup structure < Size of padding for cp_info structures insize of cp_info_dup structure < Convenient alias for DML1 < Convenient alias for DML1 < Size of padding for cp_info structures insize of cp_info_dup structure < Size of padding for cp_info structures insize of cp_info_dup structure
< Declared public; may be accessed from outside its package. < Declared final;no subclasses allowed < Treat superclass methods specially when invoked by the INVOKESPECIAL instruction < Is an interface, not a class.
< Declared
< Declared < Declared as an annotation type < Declared as an enum type < Convenient alias for DML5
< Convenient alias for DML5 < Convenient alias for DML1
< Convenient alias for DML5 < Declared public; may be accessed from outside its package.
< Declared
< Declared
< Declared < Declared final;no subclasses allowed
< Declared
< Declared
< Declared < Declared as an enum type < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML5 < Declared public; may be accessed from outside its package.
< Declared
< Declared
< Declared < Declared final;no subclasses allowed
< Declared < A bridge method, generated by the compiler. < Declared with variable number of arguments.
< Declared
< Declared
< Declared
< Declared < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML5 < Convenient alias for DML1
Definition at line 345 of file classfile.c. References ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ClassFile::access_flags, field_info::access_flags, method_info::access_flags, attribute_info_dup::ai, ALLOC_CF_ITEM, ALLOC_CP_INFO, attribute_info::attribute_name_index, field_info::attributes, method_info::attributes, ClassFile::attributes, field_info::attributes_count, method_info::attributes_count, ClassFile::attributes_count, cfattrib_atr2enum(), cfattrib_loadattribute(), cfmsgs_show_constant_pool(), cfmsgs_typemsg(), CLASSFILE_MAGIC, method_info::LOCAL_method_binding::codeatridxJVM, CONSTANT_Class, CONSTANT_CP_DEFAULT_INDEX, CONSTANT_CP_START_INDEX, CONSTANT_Double, CONSTANT_Fieldref, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodref, CONSTANT_Long, CONSTANT_Methodref, CONSTANT_NameAndType, ClassFile::constant_pool, ClassFile::constant_pool_count, CONSTANT_String, CONSTANT_Utf8, CP_INFO_NUM_EMPTIES, CP_ITEM_SWAP_U2, CP_ITEM_SWAP_U4, CP_TAG, CPIDX_RANGE_CHECK, CPTYPEIDX_RANGE_CHECK, field_info::descriptor_index, method_info::descriptor_index, DMLNORM, method_info::LOCAL_method_binding::excpatridxJVM, ClassFile::fields, ClassFile::fields_count, FILL_INFO_DUP0, FILL_INFO_DUP1, FILL_INFO_DUP2, field_info::LOCAL_field_binding::fluidxJVM, GENERIC_FAILURE1_PTR, GETRI4, GETRS2, HEAP_FREE_METHOD, HEAP_GET_METHOD, ClassFile::interfaces, ClassFile::interfaces_count, jvm_attribute_index_bad, jvm_class_index_null, jvm_field_index_bad, jvm_method_index_bad, jvm_native_method_ordinal_null, LOAD_SYSCALL_FAILURE, LOCAL_ANNOTATIONDEFAULT_ATTRIBUTE, LOCAL_BASETYPE_ERROR, LOCAL_CODE_ATTRIBUTE, LOCAL_CONSTANTVALUE_ATTRIBUTE, LOCAL_DEPRECATED_ATTRIBUTE, LOCAL_ENCLOSINGMETHOD_ATTRIBUTE, LOCAL_EXCEPTIONS_ATTRIBUTE, field_info::LOCAL_field_binding, LOCAL_INNERCLASSES_ATTRIBUTE, LOCAL_LINENUMBERTABLE_ATTRIBUTE, LOCAL_LOCALVARIABLETABLE_ATTRIBUTE, LOCAL_LOCALVARIABLETYPETABLE_ATTRIBUTE, method_info::LOCAL_method_binding, LOCAL_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, LOCAL_SIGNATURE_ATTRIBUTE, LOCAL_SOURCEFILE_ATTRIBUTE, LOCAL_SYNTHETIC_ATTRIBUTE, LOCAL_UNKNOWN_ATTRIBUTE, MACHINE_JINT_SWAP, MACHINE_JSHORT_SWAP, ClassFile::magic, ClassFile::major_version, MAKE_PU2, MAKE_PU4, ClassFile::methods, ClassFile::methods_count, ClassFile::minor_version, field_info::name_index, method_info::name_index, method_info::LOCAL_method_binding::nmordJVM, PTR_THIS_CP_Class, PTR_THIS_CP_Fieldref, PTR_THIS_CP_InterfaceMethodref, PTR_THIS_CP_Methodref, PTR_THIS_CP_Utf8, rfalse, rneither_true_nor_false, rnull, rtrue, ClassFile::super_class, sysDbgMsg(), ClassFile::this_class, VERSION_MAJOR_HIGH, VERSION_MAJOR_LOW, and VERSION_MINOR_HIGH. |
|
Release all heap allocated to a fully loaded ClassFile structure.
java.lang.Object
Definition at line 1493 of file classfile.c. |
|
Read a JVM class file. If a valid class file is read, return pointer to memory area containing its Java class image. < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML1 < Convenient alias for DML5 Definition at line 1700 of file classfile.c. |
|
Read an entire JAR file into temporary disk area and load up one class file from it. If a valid JAR file is read, return pointer to memory area containing the JAva class image of the startup class that was specified in Jar Manifest file. In the future, all classes in the JAR file will be available for loading from the temporary disk area via CLASSPATH.
< Convenient size for a
< Convenient size for a
< Convenient size for a
Definition at line 1763 of file classfile.c. |
|
Definition at line 63 of file classfile.c. |