2015-07-07 Andrew MacLeod <amacleod@redhat.com> * tree-core.h: Include symtab.h. * rtl.h: Include hard-reg-set.h but not flags.h. (HARD_CONST): Remove condition compilation involving HARD_CONST since hard-reg-set.h is always included. * regs.h: Don't include hard-reg-set.h or rtl.h. * cfg.h: Include dominance.h. * gimple.h: Include tree-ssa-alias.h and gimple-expr.h. * backend.h: New. Aggregate commonly used backend header files. * gimple-ssa.h: Don't include tree-hasher.h. * ssa.h: New. Aggregate commonly used SSA header files. * regset.h: Remove bitmap.h and hard-reg-set.h #includes. * sel-sched-ir.h: Flatten includes. * lra-int.h: Flatten completely. * sel-sched-dump.h: Flatten includes. * ira-int.h: Flatten includes. * gimple-streamer.h: Remove all includes. * cfgloop.h: Remove all #includes except cfgloopmanip.h. * resource.h: Flatten hard-reg-set.h and df.h. * sched-int.h: Flatten insn-arrt.h and df.h. * valtrack.h: flatten bitmap.h, df.h, and rtl.h * df.h: Flatten includes, leaving regset.h, alloc-pool.h and timevar.h. * genattrtab.c (write_header): Adjust generated includes. * genautomata.c (main): Likewise. * genconditions.c (write-header): Likewise. * genemit.c (main): Likewise. * gengtype.c (open_base_files): Likewise. * genopinit.c (main): Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c (main): Likewise. * genpreds.c (write_insn_preds_c): Likewise. * genrecog.c (write_header): Likewise. * alias.c: Adjust includes. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dfp.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcc-plugin.h: Likewise. * gcse-common.c: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-blocking.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-isl-ast-to-gimple.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * init-regs.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mcf.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omega.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * print-rtl.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sched-vis.c: Likewise. * sdbout.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-browser.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * valtrack.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vmsdbgout.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/aarch64/cortex-a57-fma-steering.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/aarch-common.c: Likewise. * config/arm/arm-builtins.c: Likewise. * config/arm/arm-c.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-c.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin-c.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/ft32/ft32.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386-c.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/msformat-c.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/i386/winnt-stubs.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64-c.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c-pragma.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze-c.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430-c.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/nvptx/nvptx.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78-c.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000-c.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390-c.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh-c.c: Likewise. * config/sh/sh-mem.cc: Likewise. * config/sh/sh.c: Likewise. * config/sh/sh_optimize_sett_clrt.cc: Likewise. * config/sh/sh_treg_combine.cc: Likewise. * config/sol2-c.c: Likewise. * config/sol2-cxx.c: Likewise. * config/sol2-stubs.c: Likewise. * config/sol2.c: Likewise. * config/sparc/sparc-c.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu-c.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/mul-tables.c: Likewise. * config/tilegx/tilegx-c.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/mul-tables.c: Likewise. * config/tilepro/tilepro-c.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850-c.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/visium/visium.c: Likewise. * config/vms/vms-c.c: Likewise. * config/vms/vms.c: Likewise. * config/vxworks.c: Likewise. * config/xtensa/xtensa.c: Likewise. ada 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * gcc-interface/cuintp.c: Adjust includes. * gcc-interface/decl.c: Likewise. * gcc-interface/misc.c: Likewise. * gcc-interface/targtyps.c: Likewise. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. * gcc-interface/utils2.c: Likewise. c 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * c-array-notation.c: Adjust includes. * c-aux-info.c: Likewise. * c-convert.c: Likewise. * c-decl.c: Likewise. * c-errors.c: Likewise. * c-lang.c: Likewise. * c-objc-common.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. c-family 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * array-notation-common.c: Adjust includes. * c-ada-spec.c: Likewise. * c-cilkplus.c: Likewise. * c-common.h: Likewise. * c-cppbuiltin.c: Likewise. * c-dump.c: Likewise. * c-format.c: Likewise. * c-gimplify.c: Likewise. * c-indentation.c: Likewise. * c-lex.c: Likewise. * c-omp.c: Likewise. * c-opts.c: Likewise. * c-pch.c: Likewise. * c-ppoutput.c: Likewise. * c-pragma.c: Likewise. * c-pretty-print.c: Likewise. * c-semantics.c: Likewise. * c-ubsan.c: Likewise. * cilk.c: Likewise. * stub-objc.c: Likewise. cp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * call.c: Adjust includes. * class.c: Likewise. * constexpr.c: Likewise. * cp-array-notation.c: Likewise. * cp-gimplify.c: Likewise. * cp-lang.c: Likewise. * cp-objcp-common.c: Likewise. * cp-ubsan.c: Likewise. * cvt.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * dump.c: Likewise. * error.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * friend.c: Likewise. * init.c: Likewise. * lambda.c: Likewise. * lex.c: Likewise. * mangle.c: Likewise. * method.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * ptree.c: Likewise. * repo.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. fortran 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * convert.c: Adjust includes. * cpp.c: Likewise. * decl.c: Likewise. * f95-lang.c: Likewise. * iresolve.c: Likewise. * match.c: Likewise. * module.c: Likewise. * options.c: Likewise. * target-memory.c: Likewise. * trans-array.c: Likewise. * trans-common.c: Likewise. * trans-const.c: Likewise. * trans-decl.c: Likewise. * trans-expr.c: Likewise. * trans-intrinsic.c: Likewise. * trans-io.c: Likewise. * trans-openmp.c: Likewise. * trans-stmt.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. go 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * go-backend.c: Adjust includes. * go-gcc.cc: Likewise. * go-lang.c: Likewise. java 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * boehm.c: Adjust includes. * builtins.c: Likewise. * class.c: Likewise. * constants.c: Likewise. * decl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * java-gimplify.c: Likewise. * jcf-dump.c: Likewise. * jcf-io.c: Likewise. * jcf-parse.c: Likewise. * jvgenmain.c: Likewise. * lang.c: Likewise. * mangle.c: Likewise. * mangle_name.c: Likewise. * resource.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. jit 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * dummy-frontend.c: Adjust includes. * jit-common.h: Likewise. * jit-playback.c: Likewise. lto 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * lto-lang.c: Adjust includes. * lto-object.c: Likewise. * lto-partition.c: Likewise. * lto-symtab.c: Likewise. * lto.c: Likewise. objc 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objc-act.c: Adjust includes. * objc-encoding.c: Likewise. * objc-gnu-runtime-abi-01.c: Likewise. * objc-lang.c: Likewise. * objc-map.c: Likewise. * objc-next-runtime-abi-01.c: Likewise. * objc-next-runtime-abi-02.c: Likewise. * objc-runtime-shared-support.c: Likewise. objcp 2015-07-07 Andrew MacLeod <amacleod@redhat.com> * objcp-decl.c: Adjust includes. * objcp-lang.c: Likewise. From-SVN: r225531
617 lines
17 KiB
C
617 lines
17 KiB
C
/* Handle the constant pool of the Java(TM) Virtual Machine.
|
|
Copyright (C) 1997-2015 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 "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tm.h"
|
|
#include "jcf.h"
|
|
#include "alias.h"
|
|
#include "tree.h"
|
|
#include "fold-const.h"
|
|
#include "stringpool.h"
|
|
#include "stor-layout.h"
|
|
#include "java-tree.h"
|
|
#include "diagnostic-core.h"
|
|
#include "toplev.h"
|
|
|
|
static void set_constant_entry (CPool *, int, int, jword);
|
|
static int find_tree_constant (CPool *, int, tree);
|
|
static int find_name_and_type_constant (CPool *, tree, tree);
|
|
static tree get_tag_node (int);
|
|
|
|
/* Set the INDEX'th constant in CPOOL to have the given TAG and VALUE. */
|
|
|
|
static void
|
|
set_constant_entry (CPool *cpool, int index, int tag, jword value)
|
|
{
|
|
if (cpool->data == NULL)
|
|
{
|
|
cpool->capacity = 100;
|
|
cpool->tags = ggc_cleared_vec_alloc<uint8> (cpool->capacity);
|
|
cpool->data = ggc_cleared_vec_alloc<cpool_entry> (cpool->capacity);
|
|
cpool->count = 1;
|
|
}
|
|
if (index >= cpool->capacity)
|
|
{
|
|
int old_cap = cpool->capacity;
|
|
cpool->capacity *= 2;
|
|
if (index >= cpool->capacity)
|
|
cpool->capacity = index + 10;
|
|
cpool->tags = GGC_RESIZEVEC (uint8, cpool->tags, cpool->capacity);
|
|
cpool->data = GGC_RESIZEVEC (union cpool_entry, cpool->data,
|
|
cpool->capacity);
|
|
|
|
/* Make sure GC never sees uninitialized tag values. */
|
|
memset (cpool->tags + old_cap, 0, cpool->capacity - old_cap);
|
|
memset (cpool->data + old_cap, 0,
|
|
(cpool->capacity - old_cap) * sizeof (union cpool_entry));
|
|
}
|
|
if (index >= cpool->count)
|
|
cpool->count = index + 1;
|
|
cpool->tags[index] = tag;
|
|
cpool->data[index].w = value;
|
|
}
|
|
|
|
/* Find (or create) a constant pool entry matching TAG and VALUE. */
|
|
|
|
int
|
|
find_constant1 (CPool *cpool, int tag, jword value)
|
|
{
|
|
int i;
|
|
for (i = cpool->count; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag && cpool->data[i].w == value)
|
|
return i;
|
|
}
|
|
i = cpool->count == 0 ? 1 : cpool->count;
|
|
set_constant_entry (cpool, i, tag, value);
|
|
return i;
|
|
}
|
|
|
|
/* Find a double-word constant pool entry matching TAG and WORD1/WORD2. */
|
|
|
|
int
|
|
find_constant2 (CPool *cpool, int tag, jword word1, jword word2)
|
|
{
|
|
int i;
|
|
for (i = cpool->count - 1; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag
|
|
&& cpool->data[i].w == word1
|
|
&& cpool->data[i+1].w == word2)
|
|
return i;
|
|
}
|
|
i = cpool->count == 0 ? 1 : cpool->count;
|
|
set_constant_entry (cpool, i, tag, word1);
|
|
set_constant_entry (cpool, i+1, 0, word2);
|
|
return i;
|
|
}
|
|
|
|
static int
|
|
find_tree_constant (CPool *cpool, int tag, tree value)
|
|
{
|
|
int i;
|
|
for (i = cpool->count; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag && cpool->data[i].t == value)
|
|
return i;
|
|
}
|
|
i = cpool->count == 0 ? 1 : cpool->count;
|
|
set_constant_entry (cpool, i, tag, 0);
|
|
cpool->data[i].t = value;
|
|
return i;
|
|
}
|
|
|
|
|
|
int
|
|
find_utf8_constant (CPool *cpool, tree name)
|
|
{
|
|
if (name == NULL_TREE)
|
|
return 0;
|
|
return find_tree_constant (cpool, CONSTANT_Utf8, name);
|
|
}
|
|
|
|
int
|
|
find_class_or_string_constant (CPool *cpool, int tag, tree name)
|
|
{
|
|
jword j = find_utf8_constant (cpool, name);
|
|
int i;
|
|
for (i = cpool->count; --i > 0; )
|
|
{
|
|
if (cpool->tags[i] == tag && cpool->data[i].w == j)
|
|
return i;
|
|
}
|
|
i = cpool->count;
|
|
set_constant_entry (cpool, i, tag, j);
|
|
return i;
|
|
}
|
|
|
|
int
|
|
find_class_constant (CPool *cpool, tree type)
|
|
{
|
|
return find_class_or_string_constant (cpool, CONSTANT_Class,
|
|
build_internal_class_name (type));
|
|
}
|
|
|
|
/* Allocate a CONSTANT_string entry given a STRING_CST. */
|
|
|
|
int
|
|
find_string_constant (CPool *cpool, tree string)
|
|
{
|
|
string = get_identifier (TREE_STRING_POINTER (string));
|
|
return find_class_or_string_constant (cpool, CONSTANT_String, string);
|
|
|
|
}
|
|
|
|
/* Find (or create) a CONSTANT_NameAndType matching NAME and TYPE.
|
|
Return its index in the constant pool CPOOL. */
|
|
|
|
static int
|
|
find_name_and_type_constant (CPool *cpool, tree name, tree type)
|
|
{
|
|
int name_index = find_utf8_constant (cpool, name);
|
|
int type_index = find_utf8_constant (cpool, build_java_signature (type));
|
|
return find_constant1 (cpool, CONSTANT_NameAndType,
|
|
(name_index << 16) | type_index);
|
|
}
|
|
|
|
/* Find (or create) a CONSTANT_Fieldref for DECL (a FIELD_DECL or VAR_DECL).
|
|
Return its index in the constant pool CPOOL. */
|
|
|
|
int
|
|
find_fieldref_index (CPool *cpool, tree decl)
|
|
{
|
|
int class_index = find_class_constant (cpool, DECL_CONTEXT (decl));
|
|
int name_type_index
|
|
= find_name_and_type_constant (cpool, DECL_NAME (decl), TREE_TYPE (decl));
|
|
return find_constant1 (cpool, CONSTANT_Fieldref,
|
|
(class_index << 16) | name_type_index);
|
|
}
|
|
|
|
/* Find (or create) a CONSTANT_Methodref for DECL (a FUNCTION_DECL).
|
|
Return its index in the constant pool CPOOL. */
|
|
|
|
int
|
|
find_methodref_index (CPool *cpool, tree decl)
|
|
{
|
|
return find_methodref_with_class_index (cpool, decl, DECL_CONTEXT (decl));
|
|
}
|
|
|
|
int
|
|
find_methodref_with_class_index (CPool *cpool, tree decl, tree mclass)
|
|
{
|
|
int class_index = find_class_constant (cpool, mclass);
|
|
tree name = DECL_CONSTRUCTOR_P (decl) ? init_identifier_node
|
|
: DECL_NAME (decl);
|
|
int name_type_index;
|
|
name_type_index =
|
|
find_name_and_type_constant (cpool, name, TREE_TYPE (decl));
|
|
return find_constant1 (cpool,
|
|
CLASS_INTERFACE (TYPE_NAME (mclass))
|
|
? CONSTANT_InterfaceMethodref
|
|
: CONSTANT_Methodref,
|
|
(class_index << 16) | name_type_index);
|
|
}
|
|
|
|
#define PUT1(X) (*ptr++ = (X))
|
|
#define PUT2(X) (PUT1((X) >> 8), PUT1(X))
|
|
#define PUT4(X) (PUT2((X) >> 16), PUT2(X))
|
|
#define PUTN(P, N) (memcpy(ptr, (P), (N)), ptr += (N))
|
|
|
|
/* Give the number of bytes needed in a .class file for the CPOOL
|
|
constant pool. Includes the 2-byte constant_pool_count. */
|
|
|
|
int
|
|
count_constant_pool_bytes (CPool *cpool)
|
|
{
|
|
int size = 2;
|
|
int i = 1;
|
|
for ( ; i < cpool->count; i++)
|
|
{
|
|
size++;
|
|
switch (cpool->tags[i])
|
|
{
|
|
case CONSTANT_NameAndType:
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
case CONSTANT_Float:
|
|
case CONSTANT_Integer:
|
|
size += 4;
|
|
break;
|
|
case CONSTANT_Class:
|
|
case CONSTANT_String:
|
|
size += 2;
|
|
break;
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Double:
|
|
size += 8;
|
|
i++;
|
|
break;
|
|
case CONSTANT_Utf8:
|
|
{
|
|
tree t = cpool->data[i].t;
|
|
int len = IDENTIFIER_LENGTH (t);
|
|
size += len + 2;
|
|
}
|
|
break;
|
|
default:
|
|
/* Second word of CONSTANT_Long and CONSTANT_Double. */
|
|
size--;
|
|
}
|
|
}
|
|
return size;
|
|
}
|
|
|
|
/* Write the constant pool CPOOL into BUFFER.
|
|
The length of BUFFER is LENGTH, which must match the needed length. */
|
|
|
|
void
|
|
write_constant_pool (CPool *cpool, unsigned char *buffer, int length)
|
|
{
|
|
unsigned char *ptr = buffer;
|
|
int i = 1;
|
|
union cpool_entry *datap = &cpool->data[1];
|
|
PUT2 (cpool->count);
|
|
for ( ; i < cpool->count; i++, datap++)
|
|
{
|
|
int tag = cpool->tags[i];
|
|
PUT1 (tag);
|
|
switch (tag)
|
|
{
|
|
case CONSTANT_NameAndType:
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
case CONSTANT_Float:
|
|
case CONSTANT_Integer:
|
|
PUT4 (datap->w);
|
|
break;
|
|
case CONSTANT_Class:
|
|
case CONSTANT_String:
|
|
PUT2 (datap->w);
|
|
break;
|
|
break;
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Double:
|
|
PUT4(datap->w);
|
|
i++;
|
|
datap++;
|
|
PUT4 (datap->w);
|
|
break;
|
|
case CONSTANT_Utf8:
|
|
{
|
|
tree t = datap->t;
|
|
int len = IDENTIFIER_LENGTH (t);
|
|
PUT2 (len);
|
|
PUTN (IDENTIFIER_POINTER (t), len);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
gcc_assert (ptr == buffer + length);
|
|
}
|
|
|
|
static GTY(()) tree tag_nodes[13];
|
|
static tree
|
|
get_tag_node (int tag)
|
|
{
|
|
/* A Cache for build_int_cst (CONSTANT_XXX, 0). */
|
|
|
|
if (tag >= 13)
|
|
return build_int_cst (NULL_TREE, tag);
|
|
|
|
if (tag_nodes[tag] == NULL_TREE)
|
|
tag_nodes[tag] = build_int_cst (NULL_TREE, tag);
|
|
return tag_nodes[tag];
|
|
}
|
|
|
|
/* Given a class, return its constant pool, creating one if necessary. */
|
|
|
|
CPool *
|
|
cpool_for_class (tree klass)
|
|
{
|
|
CPool *cpool = TYPE_CPOOL (klass);
|
|
|
|
if (cpool == NULL)
|
|
{
|
|
cpool = ggc_cleared_alloc<CPool> ();
|
|
TYPE_CPOOL (klass) = cpool;
|
|
}
|
|
return cpool;
|
|
}
|
|
|
|
/* Look for a constant pool entry that matches TAG and NAME.
|
|
Creates a new entry if not found.
|
|
TAG is one of CONSTANT_Utf8, CONSTANT_String or CONSTANT_Class.
|
|
NAME is an IDENTIFIER_NODE naming the Utf8 constant, string, or class.
|
|
Returns the index of the entry. */
|
|
|
|
int
|
|
alloc_name_constant (int tag, tree name)
|
|
{
|
|
CPool *outgoing_cpool = cpool_for_class (output_class);
|
|
return find_tree_constant (outgoing_cpool, tag, name);
|
|
}
|
|
|
|
/* Create a constant pool entry for a name_and_type. This one has '.'
|
|
rather than '/' because it isn't going into a class file, it's
|
|
going into a compiled object. We don't use the '/' separator in
|
|
compiled objects. */
|
|
|
|
static int
|
|
find_name_and_type_constant_tree (CPool *cpool, tree name, tree type)
|
|
{
|
|
int name_index = find_utf8_constant (cpool, name);
|
|
int type_index
|
|
= find_utf8_constant (cpool,
|
|
identifier_subst (build_java_signature (type),
|
|
"", '/', '.', ""));
|
|
return find_constant1 (cpool, CONSTANT_NameAndType,
|
|
(name_index << 16) | type_index);
|
|
}
|
|
|
|
/* Look for a field ref that matches DECL in the constant pool of
|
|
KLASS.
|
|
Return the index of the entry. */
|
|
|
|
int
|
|
alloc_constant_fieldref (tree klass, tree decl)
|
|
{
|
|
CPool *outgoing_cpool = cpool_for_class (klass);
|
|
int class_index
|
|
= find_tree_constant (outgoing_cpool, CONSTANT_Class,
|
|
DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))));
|
|
int name_type_index
|
|
= find_name_and_type_constant_tree (outgoing_cpool, DECL_NAME (decl),
|
|
TREE_TYPE (decl));
|
|
return find_constant1 (outgoing_cpool, CONSTANT_Fieldref,
|
|
(class_index << 16) | name_type_index);
|
|
}
|
|
|
|
/* Build an identifier for the internal name of reference type TYPE. */
|
|
|
|
tree
|
|
build_internal_class_name (tree type)
|
|
{
|
|
tree name;
|
|
if (TYPE_ARRAY_P (type))
|
|
name = build_java_signature (type);
|
|
else
|
|
{
|
|
name = TYPE_NAME (type);
|
|
if (TREE_CODE (name) != IDENTIFIER_NODE)
|
|
name = DECL_NAME (name);
|
|
name = identifier_subst (name, "", '.', '/', "");
|
|
}
|
|
return name;
|
|
}
|
|
|
|
/* Look for a CONSTANT_Class entry for CLAS, creating a new one if needed. */
|
|
|
|
int
|
|
alloc_class_constant (tree clas)
|
|
{
|
|
tree class_name = build_internal_class_name (clas);
|
|
|
|
return alloc_name_constant (CONSTANT_Class,
|
|
(unmangle_classname
|
|
(IDENTIFIER_POINTER(class_name),
|
|
IDENTIFIER_LENGTH(class_name))));
|
|
}
|
|
|
|
/* Return the decl of the data array of the current constant pool. */
|
|
|
|
tree
|
|
build_constant_data_ref (bool indirect)
|
|
{
|
|
if (indirect)
|
|
{
|
|
tree d;
|
|
tree cpool_type = build_array_type (ptr_type_node, NULL_TREE);
|
|
tree decl = build_class_ref (output_class);
|
|
tree klass = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (decl)),
|
|
decl);
|
|
tree constants = build3 (COMPONENT_REF,
|
|
TREE_TYPE (constants_field_decl_node), klass,
|
|
constants_field_decl_node,
|
|
NULL_TREE);
|
|
tree data = build3 (COMPONENT_REF,
|
|
TREE_TYPE (constants_data_field_decl_node),
|
|
constants,
|
|
constants_data_field_decl_node,
|
|
NULL_TREE);
|
|
|
|
TREE_THIS_NOTRAP (klass) = 1;
|
|
data = fold_convert (build_pointer_type (cpool_type), data);
|
|
d = build1 (INDIRECT_REF, cpool_type, data);
|
|
|
|
return d;
|
|
}
|
|
else
|
|
{
|
|
tree decl_name = mangled_classname ("_CD_", output_class);
|
|
tree decl = IDENTIFIER_GLOBAL_VALUE (decl_name);
|
|
|
|
if (! decl)
|
|
{
|
|
/* Build a type with unspecified bounds. The will make sure
|
|
that targets do the right thing with whatever size we end
|
|
up with at the end. Using bounds that are too small risks
|
|
assuming the data is in the small data section. */
|
|
tree type = build_array_type (ptr_type_node, NULL_TREE);
|
|
|
|
/* We need to lay out the type ourselves, since build_array_type
|
|
thinks the type is incomplete. */
|
|
layout_type (type);
|
|
|
|
decl = build_decl (input_location, VAR_DECL, decl_name, type);
|
|
TREE_STATIC (decl) = 1;
|
|
IDENTIFIER_GLOBAL_VALUE (decl_name) = decl;
|
|
}
|
|
|
|
return decl;
|
|
}
|
|
}
|
|
|
|
/* Get the pointer value at the INDEX'th element of the constant pool. */
|
|
|
|
tree
|
|
build_ref_from_constant_pool (int index)
|
|
{
|
|
tree i;
|
|
tree d = TYPE_CPOOL_DATA_REF (output_class);
|
|
|
|
if (d == NULL_TREE)
|
|
d = build_constant_data_ref (flag_indirect_classes);
|
|
|
|
i = build_int_cst (NULL_TREE, index);
|
|
d = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (d)), d, i,
|
|
NULL_TREE, NULL_TREE);
|
|
return d;
|
|
}
|
|
|
|
/* Build an initializer for the constants field of the current constant pool.
|
|
Should only be called at top-level, since it may emit declarations. */
|
|
|
|
tree
|
|
build_constants_constructor (void)
|
|
{
|
|
CPool *outgoing_cpool = cpool_for_class (current_class);
|
|
tree tags_value, data_value;
|
|
tree cons;
|
|
vec<constructor_elt, va_gc> *v = NULL;
|
|
int i;
|
|
vec<constructor_elt, va_gc> *tags = NULL;
|
|
vec<constructor_elt, va_gc> *data = NULL;
|
|
constructor_elt *t = NULL;
|
|
constructor_elt *d = NULL;
|
|
|
|
if (outgoing_cpool->count > 0)
|
|
{
|
|
int c = outgoing_cpool->count;
|
|
vec_safe_grow_cleared (tags, c);
|
|
vec_safe_grow_cleared (data, c);
|
|
t = &(*tags)[c-1];
|
|
d = &(*data)[c-1];
|
|
}
|
|
|
|
#define CONSTRUCTOR_PREPEND_VALUE(E, V) E->value = V, E--
|
|
for (i = outgoing_cpool->count; --i > 0; )
|
|
switch (outgoing_cpool->tags[i] & ~CONSTANT_LazyFlag)
|
|
{
|
|
case CONSTANT_None: /* The second half of a Double or Long on a
|
|
32-bit target. */
|
|
case CONSTANT_Fieldref:
|
|
case CONSTANT_NameAndType:
|
|
case CONSTANT_Float:
|
|
case CONSTANT_Integer:
|
|
case CONSTANT_Double:
|
|
case CONSTANT_Long:
|
|
case CONSTANT_Methodref:
|
|
case CONSTANT_InterfaceMethodref:
|
|
{
|
|
unsigned HOST_WIDE_INT temp = outgoing_cpool->data[i].w;
|
|
|
|
/* Make sure that on a big-endian machine with 64-bit
|
|
pointers this 32-bit jint appears in the first word.
|
|
FIXME: This is a kludge. The field we're initializing is
|
|
not a scalar but a union, and that's how we should
|
|
represent it in the compiler. We should fix this. */
|
|
if (BYTES_BIG_ENDIAN)
|
|
temp <<= ((POINTER_SIZE > 32) ? POINTER_SIZE - 32 : 0);
|
|
|
|
CONSTRUCTOR_PREPEND_VALUE (t, get_tag_node (outgoing_cpool->tags[i]));
|
|
CONSTRUCTOR_PREPEND_VALUE (d, build_int_cst (ptr_type_node, temp));
|
|
}
|
|
break;
|
|
|
|
case CONSTANT_Class:
|
|
case CONSTANT_String:
|
|
case CONSTANT_Unicode:
|
|
case CONSTANT_Utf8:
|
|
CONSTRUCTOR_PREPEND_VALUE (t, get_tag_node (outgoing_cpool->tags[i]));
|
|
CONSTRUCTOR_PREPEND_VALUE (d, build_utf8_ref (outgoing_cpool->data[i].t));
|
|
break;
|
|
|
|
default:
|
|
gcc_assert (false);
|
|
}
|
|
#undef CONSTRUCTOR_PREPEND_VALUE
|
|
|
|
if (outgoing_cpool->count > 0)
|
|
{
|
|
tree data_decl, tags_decl, tags_type;
|
|
tree max_index = build_int_cst (sizetype, outgoing_cpool->count - 1);
|
|
tree index_type = build_index_type (max_index);
|
|
tree tem;
|
|
|
|
/* Add dummy 0'th element of constant pool. */
|
|
gcc_assert (t == tags->address ());
|
|
gcc_assert (d == data->address ());
|
|
t->value = get_tag_node (0);
|
|
d->value = null_pointer_node;
|
|
|
|
/* Change the type of the decl to have the proper array size.
|
|
??? Make sure to transition the old type-pointer-to list to this
|
|
new type to not invalidate all build address expressions. */
|
|
data_decl = build_constant_data_ref (false);
|
|
tem = TYPE_POINTER_TO (TREE_TYPE (data_decl));
|
|
if (!tem)
|
|
tem = build_pointer_type (TREE_TYPE (data_decl));
|
|
TYPE_POINTER_TO (TREE_TYPE (data_decl)) = NULL_TREE;
|
|
TREE_TYPE (data_decl) = build_array_type (ptr_type_node, index_type);
|
|
TYPE_POINTER_TO (TREE_TYPE (data_decl)) = tem;
|
|
DECL_INITIAL (data_decl) = build_constructor (TREE_TYPE (data_decl), data);
|
|
DECL_SIZE (data_decl) = TYPE_SIZE (TREE_TYPE (data_decl));
|
|
DECL_SIZE_UNIT (data_decl) = TYPE_SIZE_UNIT (TREE_TYPE (data_decl));
|
|
rest_of_decl_compilation (data_decl, 1, 0);
|
|
data_value = build_address_of (data_decl);
|
|
|
|
tags_type = build_array_type (unsigned_byte_type_node, index_type);
|
|
tags_decl = build_decl (input_location,
|
|
VAR_DECL, mangled_classname ("_CT_",
|
|
current_class),
|
|
tags_type);
|
|
TREE_STATIC (tags_decl) = 1;
|
|
DECL_INITIAL (tags_decl) = build_constructor (tags_type, tags);
|
|
rest_of_decl_compilation (tags_decl, 1, 0);
|
|
tags_value = build_address_of (tags_decl);
|
|
}
|
|
else
|
|
{
|
|
data_value = null_pointer_node;
|
|
tags_value = null_pointer_node;
|
|
}
|
|
START_RECORD_CONSTRUCTOR (v, constants_type_node);
|
|
PUSH_FIELD_VALUE (v, "size",
|
|
build_int_cst (NULL_TREE, outgoing_cpool->count));
|
|
PUSH_FIELD_VALUE (v, "tags", tags_value);
|
|
PUSH_FIELD_VALUE (v, "data", data_value);
|
|
FINISH_RECORD_CONSTRUCTOR (cons, v, constants_type_node);
|
|
return cons;
|
|
}
|
|
|
|
#include "gt-java-constants.h"
|