gcc/ChangeLog: * alias.c (record_alias_subset): Adjust. * bitmap.c (bitmap_element_allocate): Likewise. (bitmap_gc_alloc_stat): Likewise. * cfg.c (init_flow): Likewise. (alloc_block): Likewise. (unchecked_make_edge): Likewise. * cfgloop.c (alloc_loop): Likewise. (flow_loops_find): Likewise. (rescan_loop_exit): Likewise. * cfgrtl.c (init_rtl_bb_info): Likewise. * cgraph.c (insert_new_cgraph_node_version): Likewise. (cgraph_allocate_node): Likewise. (cgraph_create_edge_1): Likewise. (cgraph_allocate_init_indirect_info): Likewise. * cgraphclones.c (cgraph_clone_edge): Likewise. * cgraphunit.c (add_asm_node): Likewise. (init_lowered_empty_function): Likewise. * config/aarch64/aarch64.c (aarch64_init_machine_status): Likewise. * config/alpha/alpha.c (alpha_init_machine_status): Likewise. (alpha_use_linkage): Likewise. * config/arc/arc.c (arc_init_machine_status): Likewise. * config/arm/arm.c (arm_init_machine_status): Likewise. * config/avr/avr.c (avr_init_machine_status): Likewise. * config/bfin/bfin.c (bfin_init_machine_status): Likewise. * config/c6x/c6x.c (c6x_init_machine_status): Likewise. * config/cris/cris.c (cris_init_machine_status): Likewise. * config/darwin.c (machopic_indirection_name): Likewise. (darwin_build_constant_cfstring): Likewise. (darwin_enter_string_into_cfstring_table): Likewise. * config/epiphany/epiphany.c (epiphany_init_machine_status): * Likewise. * config/frv/frv.c (frv_init_machine_status): Likewise. * config/i386/i386.c (get_dllimport_decl): Likewise. (ix86_init_machine_status): Likewise. (assign_386_stack_local): Likewise. * config/i386/winnt.c (i386_pe_record_external_function): Likewise. (i386_pe_maybe_record_exported_symbol): Likewise. (i386_pe_record_stub): Likewise. * config/ia64/ia64.c (ia64_init_machine_status): Likewise. * config/iq2000/iq2000.c (iq2000_init_machine_status): Likewise. * config/m32c/m32c.c (m32c_init_machine_status): Likewise. (m32c_note_pragma_address): Likewise. * config/mep/mep.c (mep_init_machine_status): Likewise. (mep_note_pragma_flag): Likewise. * config/mips/mips.c (mflip_mips16_use_mips16_p): Likewise. (mips16_local_alias): Likewise. (mips_init_machine_status): Likewise. * config/mmix/mmix.c (mmix_init_machine_status): Likewise. * config/moxie/moxie.c (moxie_init_machine_status): Likewise. * config/msp430/msp430.c (msp430_init_machine_status): Likewise. * config/nds32/nds32.c (nds32_init_machine_status): Likewise. * config/nios2/nios2.c (nios2_init_machine_status): Likewise. * config/pa/pa.c (pa_init_machine_status): Likewise. (pa_get_deferred_plabel): Likewise. * config/rl78/rl78.c (rl78_init_machine_status): Likewise. * config/rs6000/rs6000.c (builtin_function_type): Likewise. (rs6000_init_machine_status): Likewise. (output_toc): Likewise. * config/s390/s390.c (s390_init_machine_status): Likewise. * config/score/score.c (score_output_external): Likewise. * config/sparc/sparc.c (sparc_init_machine_status): Likewise. * config/spu/spu.c (spu_init_machine_status): Likewise. * config/tilegx/tilegx.c (tilegx_init_machine_status): Likewise. * config/tilepro/tilepro.c (tilepro_init_machine_status): * Likewise. * config/xtensa/xtensa.c (xtensa_init_machine_status): Likewise. * coverage.c (coverage_end_function): Likewise. * dbxout.c (dbxout_init): Likewise. * doc/gty.texi: Don't mention variable_size attribute. * dwarf2cfi.c (new_cfi): Adjust. (new_cfi_row): Likewise. (copy_cfi_row): Likewise. (create_cie_data): Likewise. * dwarf2out.c (dwarf2out_alloc_current_fde): Likewise. (new_loc_descr): Likewise. (find_AT_string_in_table): Likewise. (add_addr_table_entry): Likewise. (new_die): Likewise. (add_var_loc_to_decl): Likewise. (clone_die): Likewise. (clone_as_declaration): Likewise. (break_out_comdat_types): Likewise. (new_loc_list): Likewise. (add_loc_descr_to_each): Likewise. (add_location_or_const_value_attribute): Likewise. (add_linkage_name): Likewise. (lookup_filename): Likewise. (dwarf2out_var_location): Likewise. (new_line_info_table): Likewise. (dwarf2out_init): Likewise. (mem_loc_descriptor): Likewise. (loc_descriptor): Likewise. (add_const_value_attribute): Likewise. (tree_add_const_value_attribute): Likewise. (comp_dir_string): Likewise. (dwarf2out_vms_debug_main_pointer): Likewise. (string_cst_pool_decl): Likewise. * emit-rtl.c (set_mem_attrs): Likewise. (get_reg_attrs): Likewise. (start_sequence): Likewise. (init_emit): Likewise. (init_emit_regs): Likewise. * except.c (init_eh_for_function): Likewise. (gen_eh_region): Likewise. (gen_eh_region_catch): Likewise. (gen_eh_landing_pad): Likewise. (add_call_site): Likewise. * function.c (add_frame_space): Likewise. (insert_temp_slot_address): Likewise. (assign_stack_temp_for_type): Likewise. (get_hard_reg_initial_val): Likewise. (allocate_struct_function): Likewise. (prepare_function_start): Likewise. (types_used_by_var_decl_insert): Likewise. * gengtype.c (variable_size_p): Remove function. (enum alloc_quantity): Remove enum. (write_typed_alloc_def): Remove function. (write_typed_struct_alloc_def): Likewise. (write_typed_typedef_alloc_def): Likewise. (write_typed_alloc_defns): Likewise. (main): Adjust. * ggc-common.c (ggc_cleared_alloc_htab_ignore_args): Adjust. (ggc_cleared_alloc_ptr_array_two_args): Likewise. * ggc.h (ggc_alloc): new function. (ggc_cleared_alloc): Likewise. (ggc_vec_alloc): Template on type of vector element, and remove element size argument. (ggc_cleared_vec_alloc): Likewise. * gimple.c (gimple_build_omp_for): Adjust. (gimple_copy): Likewise. * ipa-cp.c (get_replacement_map): Likewise. (find_aggregate_values_for_callers_subset): Likewise. (known_aggs_to_agg_replacement_list): Likewise. * ipa-devirt.c (get_odr_type): Likewise. * ipa-prop.c (ipa_node_duplication_hook): Likewise. (read_agg_replacement_chain): Likewise. * loop-iv.c (get_simple_loop_desc): Likewise. * lto-cgraph.c (input_node_opt_summary): Likewise. * lto-section-in.c (lto_new_in_decl_state): Likewise. * lto-streamer-in.c (lto_input_eh_catch_list): Likewise. (input_eh_region): Likewise. (input_eh_lp): Likewise. (input_cfg): Likewise. * optabs.c (set_optab_libfunc): Likewise. (init_tree_optimization_optabs): Likewise. (set_conv_libfunc): Likewise. * passes.c (do_per_function_toporder): Likewise. * rtl.h: Don't use variable_size gty attribute. * sese.c (if_region_set_false_region): Adjust. * stringpool.c (gt_pch_save_stringpool): Likewise. * target-globals.c (save_target_globals): Likewise. * toplev.c (general_init): Likewise. * trans-mem.c (record_tm_replacement): Likewise. (split_bb_make_tm_edge): Likewise. * tree-cfg.c (move_sese_region_to_fn): Likewise. * tree-data-ref.h (lambda_vector_new): Likewise. * tree-eh.c (add_stmt_to_eh_lp_fn): Likewise. * tree-iterator.c (tsi_link_before): Likewise. (tsi_link_after): Likewise. * tree-scalar-evolution.c (new_scev_info_str): Likewise. * tree-ssa-loop-niter.c (record_estimate): Likewise. * tree-ssa-operands.c (ssa_operand_alloc): Likewise. * tree-ssa-operands.h: Don't use variable_size gty attribute. * tree-ssa.c (init_tree_ssa): Adjust. * tree-ssanames.c (set_range_info): Likewise. (get_ptr_info): Likewise. (duplicate_ssa_name_ptr_info): Likewise. (duplicate_ssa_name_range_info): Likewise. * tree-streamer-in.c (unpack_ts_real_cst_value_fields): Likewise. (unpack_ts_fixed_cst_value_fields): Likewise. * tree.c (build_fixed): Likewise. (build_real): Likewise. (build_string): Likewise. (decl_priority_info): Likewise. (decl_debug_expr_insert): Likewise. (decl_value_expr_insert): Likewise. (decl_debug_args_insert): Likewise. (type_hash_add): Likewise. (build_omp_clause): Likewise. * ubsan.c (decl_for_type_insert): Likewise. * varasm.c (get_unnamed_section): Likewise. (get_noswitch_section): Likewise. (get_section): Likewise. (get_block_for_section): Likewise. (create_block_symbol): Likewise. (build_constant_desc): Likewise. (create_constant_pool): Likewise. (force_const_mem): Likewise. (record_tm_clone_pair): Likewise. * varpool.c (varpool_create_empty_node): Likewise. gcc/c/ChangeLog: * c-decl.c (finish_struct): Adjust. (finish_enum): Likewise. (bind): Adjust. (record_inline_static): Likewise. (push_scope): Likewise. (make_label): Likewise. (lookup_label_for_goto): Likewise. (finish_struct): Likewise. (finish_enum): Likewise. (store_parm_decls): Likewise. (c_push_function_context): Likewise. * c-lang.h: Remove usage of variable_size gty attribute. * c-parser.c (c_parse_init): Adjust. (c_parse_file): Likewise. gcc/java/ChangeLog: * class.c (add_method_1): Adjust. (java_treetreehash_new): Likewise. * constants.c (set_constant_entry): Likewise. (cpool_for_class): Likewise. * decl.c (make_binding_level): Likewise. (java_dup_lang_specific_decl): Likewise. * expr.c (add_type_assertion): Likewise. * java-tree.h (MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC): Likewise. (lang_decl): don't use variable_size gty attribute. (MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC): Adjust. (lang_type): Don't use variable_size gty attribute. * jcf-parse.c (java_parse_file): Adjust. (process_zip_dir): Likewise. * jcf.h: Remove usage of variable_size gty attribute. * jcf-reader.c (jcf_parse_constant_pool): Adjust. (jcf_parse_bootstrap_methods): Likewise. gcc/objc/ChangeLog: * objc-act.c (objc_build_string_object): Adjust. (continue_class): Likewise. * objc-act.h (ALLOC_OBJC_TYPE_LANG_SPECIFIC): Likewise. * objc-map.c (objc_map_alloc_ggc): Likewise. (objc_map_private_resize): Likewise. * objc-next-runtime-abi-02.c (objc_next_runtime_abi_02_init): Likewise. (hash_name_enter): Likewise. gcc/cp/ChangeLog: * class.c (sorted_fields_type_new): Adjust. * cp-cilkplus.c (cilk_install_body_with_frame_cleanup): Likewise. * cp-objcp-common.c (decl_shadowed_for_var_insert): Likewise. * cp-tree.h: Remove usage of variable_size gty attribute. * decl.c (make_label_decl): Adjust. (check_goto): Likewise. (start_preparsed_function): Likewise. (save_function_data): Likewise. * lex.c (init_reswords): Likewise. (retrofit_lang_decl): Likewise. (cxx_dup_lang_specific_decl): Likewise. (copy_lang_type): Likewise. (cxx_make_type): Likewise. * name-lookup.c (binding_entry_make): Likewise. (binding_table_construct): Likewise. (binding_table_new): Likewise. (cxx_binding_make): Likewise. (pushdecl_maybe_friend_1): Likewise. (begin_scope): Likewise. (push_to_top_level): Likewise. * parser.c (cp_lexer_alloc): Likewise. (cp_lexer_new_from_tokens): Likewise. (cp_token_cache_new): Likewise. (cp_parser_context_new): Likewise. (cp_parser_new): Likewise. (cp_parser_nested_name_specifier_opt): Likewise. (cp_parser_template_id): Likewise. * pt.c (maybe_process_partial_specialization): Likewise. (register_specialization): Likewise. (add_pending_template): Likewise. (lookup_template_class_1): Likewise. (push_tinst_level): Likewise. * semantics.c (register_constexpr_fundef): Likewise. (cxx_eval_call_expression): Likewise. * typeck2.c (abstract_virtuals_error_sfinae): Likewise. gcc/fortran/ChangeLog: * f95-lang.c (pushlevel): Adjust. * trans-decl.c (gfc_allocate_lang_decl): Adjust. (gfc_find_module): Likewise. * trans-types.c (gfc_get_nodesc_array_type): Likewise. (gfc_get_array_type_bounds): Likewise. (gfc_nonrestricted_type): Likewise. * trans.h: Don't use variable_size gty attribute. gcc/ada/ChangeLog: * gcc-interface/ada-tree.h: Remove usage of variable_size gty annotation. * gcc-interface/decl.c (annotate_value): Adjust. * gcc-interface/trans.c (Attribute_to_gnu): Likewise. (push_range_check_info): Likewise. (Loop_Statement_to_gnu): Likewise. (Subprogram_Body_to_gnu): Likewise. (Compilation_Unit_to_gnu): Likewise. (start_stmt_group): Likewise. * gcc-interface/utils.c (init_gnat_utils): Likewise. (gnat_pushlevel): Likewise. (maybe_pad_type): Likewise. gcc/go/ChangeLog: * go-lang.c (struct GTY): Don't use variable_size gty attribute. gcc/c-family/ChangeLog: * c-common.h (sorted_fields_type): Remove variable_size GTY attribute. * c-pragma.c (push_alignment): Adjust. (handle_pragma_push_options): Likewise. gcc/lto/ChangeLog: * lto-tree.h: Don't use variable_size gty attribute. * lto.c (lto_read_in_decl_state): Adjust. (create_subid_section_table): Likewise. (lto_flatten_files): Likewise. (read_cgraph_and_symbols): Likewise. gcc/objcp/ChangeLog: * objcp-decl.h: Adjust. From-SVN: r210566
577 lines
15 KiB
C
577 lines
15 KiB
C
/* This file read a Java(TM) .class file.
|
|
It is not stand-alone: It depends on tons of macros, and the
|
|
intent is you #include this file after you've defined the macros.
|
|
Copyright (C) 1996-2014 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GCC is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
Java and all Java-based marks are trademarks or registered trademarks
|
|
of Sun Microsystems, Inc. in the United States and other countries.
|
|
The Free Software Foundation is independent of Sun Microsystems, Inc. */
|
|
|
|
#include "ggc.h"
|
|
#include "jcf.h"
|
|
#include "zipfile.h"
|
|
|
|
static int get_attribute (JCF *, int, jv_attr_type);
|
|
static int jcf_parse_preamble (JCF *);
|
|
static int jcf_parse_constant_pool (JCF *);
|
|
static void jcf_parse_class (JCF *);
|
|
static int jcf_parse_fields (JCF *);
|
|
static int jcf_parse_one_method (JCF *, int);
|
|
static int jcf_parse_methods (JCF *);
|
|
static int jcf_parse_final_attributes (JCF *);
|
|
static int jcf_parse_bootstrap_methods (JCF *, int) ATTRIBUTE_UNUSED;
|
|
#ifdef NEED_PEEK_ATTRIBUTE
|
|
static int peek_attribute (JCF *, int, const char *, int);
|
|
#endif
|
|
#ifdef NEED_SKIP_ATTRIBUTE
|
|
static void skip_attribute (JCF *, int);
|
|
#endif
|
|
|
|
/* Go through all available attribute (ATTRIBUTE_NUMER) and try to
|
|
identify PEEKED_NAME. Return 1 if PEEKED_NAME was found, 0
|
|
otherwise. JCF is restored to its initial position before
|
|
returning. */
|
|
|
|
#ifdef NEED_PEEK_ATTRIBUTE /* Not everyone uses this function */
|
|
static int
|
|
peek_attribute (JCF *jcf, int attribute_number, const char *peeked_name,
|
|
int peeked_name_length)
|
|
{
|
|
int to_return = 0;
|
|
long absolute_offset = (long)JCF_TELL (jcf);
|
|
int i;
|
|
|
|
for (i = 0; !to_return && i < attribute_number; i++)
|
|
{
|
|
uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
|
|
uint32 attribute_length = JCF_readu4 (jcf);
|
|
int name_length;
|
|
const unsigned char *name_data;
|
|
|
|
JCF_FILL (jcf, (long) attribute_length);
|
|
if (attribute_name <= 0 || attribute_name >= JPOOL_SIZE(jcf)
|
|
|| JPOOL_TAG (jcf, attribute_name) != CONSTANT_Utf8)
|
|
continue;
|
|
|
|
name_length = JPOOL_UTF_LENGTH (jcf, attribute_name);
|
|
name_data = JPOOL_UTF_DATA (jcf, attribute_name);
|
|
|
|
if (name_length == peeked_name_length
|
|
&& ! memcmp (name_data, peeked_name, peeked_name_length))
|
|
{
|
|
to_return = 1;
|
|
break;
|
|
}
|
|
|
|
JCF_SKIP (jcf, attribute_length);
|
|
}
|
|
|
|
JCF_SEEK (jcf, absolute_offset);
|
|
return to_return;
|
|
}
|
|
#endif
|
|
|
|
#ifdef NEED_SKIP_ATTRIBUTE /* Not everyone uses this function */
|
|
static void
|
|
skip_attribute (JCF *jcf, int number_of_attribute)
|
|
{
|
|
while (number_of_attribute--)
|
|
{
|
|
JCF_u4 N;
|
|
JCF_FILL (jcf, 6);
|
|
(void) JCF_readu2 (jcf);
|
|
N = JCF_readu4 (jcf);
|
|
JCF_SKIP (jcf, N);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
static int
|
|
get_attribute (JCF *jcf, int index,
|
|
jv_attr_type attr_type ATTRIBUTE_UNUSED)
|
|
{
|
|
uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
|
|
uint32 attribute_length = JCF_readu4 (jcf);
|
|
uint32 start_pos = JCF_TELL(jcf);
|
|
int name_length;
|
|
const unsigned char *name_data;
|
|
JCF_FILL (jcf, (long) attribute_length);
|
|
if (attribute_name <= 0 || attribute_name >= JPOOL_SIZE(jcf))
|
|
return -2;
|
|
if (JPOOL_TAG (jcf, attribute_name) != CONSTANT_Utf8)
|
|
return -2;
|
|
name_length = JPOOL_UTF_LENGTH (jcf, attribute_name);
|
|
name_data = JPOOL_UTF_DATA (jcf, attribute_name);
|
|
|
|
#define MATCH_ATTRIBUTE(S) \
|
|
(name_length == sizeof (S)-1 && memcmp (name_data, S, sizeof (S)-1) == 0)
|
|
|
|
#ifdef IGNORE_ATTRIBUTE
|
|
if (IGNORE_ATTRIBUTE (jcf, attribute_name, attribute_length))
|
|
{
|
|
JCF_SKIP (jcf, attribute_length);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_SOURCEFILE
|
|
if (MATCH_ATTRIBUTE ("SourceFile"))
|
|
{
|
|
uint16 sourcefile_index = JCF_readu2 (jcf);
|
|
HANDLE_SOURCEFILE(sourcefile_index);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_CONSTANTVALUE
|
|
if (MATCH_ATTRIBUTE ("ConstantValue"))
|
|
{
|
|
uint16 constantvalue_index = JCF_readu2 (jcf);
|
|
if (constantvalue_index <= 0 || constantvalue_index >= JPOOL_SIZE(jcf))
|
|
return -2;
|
|
HANDLE_CONSTANTVALUE(constantvalue_index);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_CODE_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("Code"))
|
|
{
|
|
uint16 j;
|
|
uint16 max_stack ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
|
|
uint16 max_locals ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
|
|
uint32 code_length = JCF_readu4 (jcf);
|
|
uint16 exception_table_length, attributes_count;
|
|
if (code_length + 12 > attribute_length)
|
|
return -1;
|
|
HANDLE_CODE_ATTRIBUTE(max_stack, max_locals, code_length);
|
|
JCF_SKIP (jcf, code_length);
|
|
exception_table_length = JCF_readu2 (jcf);
|
|
if (code_length + 8 * exception_table_length + 12 > attribute_length)
|
|
return -1;
|
|
#ifdef HANDLE_EXCEPTION_TABLE
|
|
HANDLE_EXCEPTION_TABLE (jcf->read_ptr, exception_table_length);
|
|
#endif
|
|
JCF_SKIP (jcf, 2 * 4 * exception_table_length);
|
|
attributes_count = JCF_readu2 (jcf);
|
|
for (j = 0; j < attributes_count; j++)
|
|
{
|
|
int code = get_attribute (jcf, index, JV_METHOD_ATTR);
|
|
if (code != 0)
|
|
return code;
|
|
}
|
|
}
|
|
else
|
|
#endif /* HANDLE_CODE_ATTRIBUTE */
|
|
#ifdef HANDLE_EXCEPTIONS_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("Exceptions"))
|
|
{
|
|
uint16 count = JCF_readu2 (jcf);
|
|
HANDLE_EXCEPTIONS_ATTRIBUTE (count);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_LINENUMBERTABLE_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("LineNumberTable"))
|
|
{
|
|
uint16 count = JCF_readu2 (jcf);
|
|
HANDLE_LINENUMBERTABLE_ATTRIBUTE (count);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_LOCALVARIABLETABLE_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("LocalVariableTable"))
|
|
{
|
|
uint16 count = JCF_readu2 (jcf);
|
|
HANDLE_LOCALVARIABLETABLE_ATTRIBUTE (count);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("LocalVariableTypeTable"))
|
|
{
|
|
uint16 count = JCF_readu2 (jcf);
|
|
HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE (count);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_INNERCLASSES_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("InnerClasses"))
|
|
{
|
|
uint16 count = JCF_readu2 (jcf);
|
|
HANDLE_INNERCLASSES_ATTRIBUTE (count);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_SYNTHETIC_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("Synthetic"))
|
|
{
|
|
HANDLE_SYNTHETIC_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_GCJCOMPILED_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("gnu.gcj.gcj-compiled"))
|
|
{
|
|
HANDLE_GCJCOMPILED_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_DEPRECATED_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("Deprecated"))
|
|
{
|
|
HANDLE_DEPRECATED_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("SourceDebugExtension")) /* JSR 45 */
|
|
{
|
|
HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE (attribute_length);
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_ENCLOSINGMETHOD_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("EnclosingMethod"))
|
|
{
|
|
HANDLE_ENCLOSINGMETHOD_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_SIGNATURE_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("Signature"))
|
|
{
|
|
HANDLE_SIGNATURE_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("RuntimeVisibleAnnotations"))
|
|
{
|
|
HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("RuntimeInvisibleAnnotations"))
|
|
{
|
|
HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("RuntimeVisibleParameterAnnotations"))
|
|
{
|
|
HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("RuntimeInvisibleParameterAnnotations"))
|
|
{
|
|
HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
#ifdef HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE
|
|
if (MATCH_ATTRIBUTE ("AnnotationDefault"))
|
|
{
|
|
HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE ();
|
|
}
|
|
else
|
|
#endif
|
|
if (MATCH_ATTRIBUTE ("BootstrapMethods"))
|
|
{
|
|
#ifdef HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE
|
|
HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE();
|
|
#else
|
|
JCF_SKIP (jcf, attribute_length);
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#ifdef PROCESS_OTHER_ATTRIBUTE
|
|
PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
|
|
#else
|
|
JCF_SKIP (jcf, attribute_length);
|
|
#endif
|
|
}
|
|
if ((long) (start_pos + attribute_length) != JCF_TELL(jcf))
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
/* Read and handle the pre-amble. */
|
|
static int
|
|
jcf_parse_preamble (JCF* jcf)
|
|
{
|
|
uint32 magic = (JCF_FILL (jcf, 8), JCF_readu4 (jcf));
|
|
uint16 minor_version ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
|
|
uint16 major_version ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
|
|
#ifdef HANDLE_MAGIC
|
|
HANDLE_MAGIC (magic, minor_version, major_version);
|
|
#endif
|
|
if (magic != 0xcafebabe)
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
/* Read and handle the constant pool.
|
|
|
|
Return 0 if OK.
|
|
Return -2 if a bad cross-reference (index of other constant) was seen.
|
|
*/
|
|
static int
|
|
jcf_parse_constant_pool (JCF* jcf)
|
|
{
|
|
int i, n;
|
|
JPOOL_SIZE (jcf) = (JCF_FILL (jcf, 2), JCF_readu2 (jcf));
|
|
jcf->cpool.tags = (uint8 *) ggc_alloc_atomic (JPOOL_SIZE (jcf));
|
|
jcf->cpool.data = (cpool_entry *) ggc_internal_cleared_alloc
|
|
(sizeof (jword) * JPOOL_SIZE (jcf));
|
|
jcf->cpool.tags[0] = 0;
|
|
#ifdef HANDLE_START_CONSTANT_POOL
|
|
HANDLE_START_CONSTANT_POOL (JPOOL_SIZE (jcf));
|
|
#endif
|
|
for (i = 1; i < (int) JPOOL_SIZE (jcf); i++)
|
|
{
|
|
int constant_kind;
|
|
|
|
/* Make sure at least 9 bytes are available. This is enough
|
|
for all fixed-sized constant pool entries (so we don't need many
|
|
more JCF_FILL calls below), but is is small enough that
|
|
we are guaranteed to not hit EOF (in a valid .class file). */
|
|
JCF_FILL (jcf, 9);
|
|
constant_kind = JCF_readu (jcf);
|
|
jcf->cpool.tags[i] = constant_kind;
|
|
switch (constant_kind)
|
|
{
|
|
case CONSTANT_String:
|
|
case CONSTANT_Class:
|
|
jcf->cpool.data[i].w = JCF_readu2 (jcf);
|
|
break;
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
case CONSTANT_NameAndType:
|
|
jcf->cpool.data[i].w = JCF_readu2 (jcf);
|
|
jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
|
|
break;
|
|
case CONSTANT_Integer:
|
|
case CONSTANT_Float:
|
|
jcf->cpool.data[i].w = JCF_readu4 (jcf);
|
|
break;
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Double:
|
|
jcf->cpool.data[i].w = JCF_readu4 (jcf);
|
|
i++; /* These take up two spots in the constant pool */
|
|
jcf->cpool.tags[i] = 0;
|
|
jcf->cpool.data[i].w = JCF_readu4 (jcf);
|
|
break;
|
|
case CONSTANT_Utf8:
|
|
n = JCF_readu2 (jcf);
|
|
JCF_FILL (jcf, n);
|
|
#ifdef HANDLE_CONSTANT_Utf8
|
|
HANDLE_CONSTANT_Utf8(jcf, i, n);
|
|
#else
|
|
jcf->cpool.data[i].w = JCF_TELL(jcf) - 2;
|
|
JCF_SKIP (jcf, n);
|
|
#endif
|
|
break;
|
|
case CONSTANT_MethodHandle:
|
|
jcf->cpool.data[i].w = JCF_readu (jcf);
|
|
jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
|
|
break;
|
|
case CONSTANT_MethodType:
|
|
jcf->cpool.data[i].w = JCF_readu2 (jcf);
|
|
break;
|
|
case CONSTANT_InvokeDynamic:
|
|
jcf->cpool.data[i].w = JCF_readu2 (jcf);
|
|
jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
|
|
break;
|
|
default:
|
|
return i;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Read various class flags and numbers. */
|
|
|
|
static void
|
|
jcf_parse_class (JCF* jcf)
|
|
{
|
|
int i;
|
|
uint16 interfaces_count;
|
|
JCF_FILL (jcf, 8);
|
|
jcf->access_flags = JCF_readu2 (jcf);
|
|
jcf->this_class = JCF_readu2 (jcf);
|
|
jcf->super_class = JCF_readu2 (jcf);
|
|
interfaces_count = JCF_readu2 (jcf);
|
|
|
|
#ifdef HANDLE_CLASS_INFO
|
|
HANDLE_CLASS_INFO(jcf->access_flags, jcf->this_class, jcf->super_class, interfaces_count);
|
|
#endif
|
|
|
|
JCF_FILL (jcf, 2 * interfaces_count);
|
|
|
|
/* Read interfaces. */
|
|
for (i = 0; i < interfaces_count; i++)
|
|
{
|
|
uint16 index ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
|
|
#ifdef HANDLE_CLASS_INTERFACE
|
|
HANDLE_CLASS_INTERFACE (index);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
/* Read fields. */
|
|
static int
|
|
jcf_parse_fields (JCF* jcf)
|
|
{
|
|
int i, j;
|
|
uint16 fields_count;
|
|
JCF_FILL (jcf, 2);
|
|
fields_count = JCF_readu2 (jcf);
|
|
|
|
#ifdef HANDLE_START_FIELDS
|
|
HANDLE_START_FIELDS (fields_count);
|
|
#endif
|
|
for (i = 0; i < fields_count; i++)
|
|
{
|
|
uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
|
|
uint16 name_index = JCF_readu2 (jcf);
|
|
uint16 signature_index = JCF_readu2 (jcf);
|
|
uint16 attribute_count = JCF_readu2 (jcf);
|
|
#ifdef HANDLE_START_FIELD
|
|
HANDLE_START_FIELD (access_flags, name_index, signature_index,
|
|
attribute_count);
|
|
#endif
|
|
for (j = 0; j < attribute_count; j++)
|
|
{
|
|
int code = get_attribute (jcf, i, JV_FIELD_ATTR);
|
|
if (code != 0)
|
|
return code;
|
|
}
|
|
#ifdef HANDLE_END_FIELD
|
|
HANDLE_END_FIELD ();
|
|
#endif
|
|
}
|
|
#ifdef HANDLE_END_FIELDS
|
|
HANDLE_END_FIELDS ();
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
/* Read methods. */
|
|
|
|
static int
|
|
jcf_parse_one_method (JCF* jcf, int index)
|
|
{
|
|
int i;
|
|
uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
|
|
uint16 name_index = JCF_readu2 (jcf);
|
|
uint16 signature_index = JCF_readu2 (jcf);
|
|
uint16 attribute_count = JCF_readu2 (jcf);
|
|
#ifdef HANDLE_METHOD
|
|
HANDLE_METHOD(access_flags, name_index, signature_index, attribute_count);
|
|
#endif
|
|
for (i = 0; i < attribute_count; i++)
|
|
{
|
|
int code = get_attribute (jcf, index, JV_METHOD_ATTR);
|
|
if (code != 0)
|
|
return code;
|
|
}
|
|
#ifdef HANDLE_END_METHOD
|
|
HANDLE_END_METHOD ();
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
jcf_parse_methods (JCF* jcf)
|
|
{
|
|
int i;
|
|
uint16 methods_count;
|
|
JCF_FILL (jcf, 2);
|
|
methods_count = JCF_readu2 (jcf);
|
|
#ifdef HANDLE_START_METHODS
|
|
HANDLE_START_METHODS (methods_count);
|
|
#endif
|
|
for (i = 0; i < methods_count; i++)
|
|
{
|
|
int code = jcf_parse_one_method (jcf, i);
|
|
if (code != 0)
|
|
return code;
|
|
}
|
|
#ifdef HANDLE_END_METHODS
|
|
HANDLE_END_METHODS ();
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
/* Read attributes. */
|
|
static int
|
|
jcf_parse_final_attributes (JCF *jcf)
|
|
{
|
|
int i;
|
|
uint16 attributes_count = (JCF_FILL (jcf, 2), JCF_readu2 (jcf));
|
|
#ifdef START_FINAL_ATTRIBUTES
|
|
START_FINAL_ATTRIBUTES (attributes_count)
|
|
#endif
|
|
for (i = 0; i < attributes_count; i++)
|
|
{
|
|
int code = get_attribute (jcf, i, JV_CLASS_ATTR);
|
|
if (code != 0)
|
|
return code;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Read and handle the "BootstrapMethods" attribute.
|
|
|
|
Return 0 if OK.
|
|
*/
|
|
static int
|
|
jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED)
|
|
{
|
|
int i;
|
|
uint16 num_methods = JCF_readu2 (jcf);
|
|
jcf->bootstrap_methods.count = num_methods;
|
|
jcf->bootstrap_methods.methods = ggc_vec_alloc<bootstrap_method> (num_methods);
|
|
#ifdef HANDLE_START_BOOTSTRAP_METHODS
|
|
HANDLE_START_BOOTSTRAP_METHODS (jcf, num_methods);
|
|
#endif
|
|
|
|
for (i = 0; i < num_methods; i++)
|
|
{
|
|
unsigned j;
|
|
bootstrap_method *m = &jcf->bootstrap_methods.methods[i];
|
|
m->method_ref = JCF_readu2 (jcf);
|
|
m->num_arguments = JCF_readu2 (jcf);
|
|
m->bootstrap_arguments = ggc_vec_alloc<unsigned> (m->num_arguments);
|
|
for (j = 0; j < m->num_arguments; j++)
|
|
m->bootstrap_arguments[j] = JCF_readu2 (jcf);
|
|
}
|
|
|
|
#ifdef HANDLE_END_BOOTSTRAP_METHODS
|
|
HANDLE_END_BOOTSTRAP_METHODS (num_methods);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|