1 /* src/vm/jit/jit.c - calls the code generation functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "mm/memory.h"
37 #include "native/native.h"
39 #include "toolbox/logging.h"
41 #include "threads/lock-common.h"
44 #include "vm/global.h"
45 #include "vm/globals.hpp"
46 #include "vm/initialize.h"
47 #include "vm/loader.h"
48 #include "vm/method.h"
49 #include "vm/options.h"
50 #include "vm/rt-timing.h"
51 #include "vm/statistics.h"
53 #include "vm/jit/asmpart.h"
55 #include "vm/jit/cfg.h"
57 #include "vm/jit/codegen-common.h"
58 #include "vm/jit/disass.h"
59 #include "vm/jit/dseg.h"
60 #include "vm/jit/jit.h"
61 #include "vm/jit/parse.h"
62 #include "vm/jit/reg.h"
64 #include "vm/jit/show.h"
65 #include "vm/jit/stack.h"
67 #if defined(ENABLE_OPAGENT)
68 #include "vm/jit/oprofile-agent.hpp"
71 #include "vm/jit/allocator/simplereg.h"
72 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
73 # include "vm/jit/allocator/lsra.h"
76 #if defined(ENABLE_SSA)
77 # include "vm/jit/optimizing/lsra.h"
78 # include "vm/jit/optimizing/ssa.h"
81 #if defined(ENABLE_INLINING)
82 # include "vm/jit/inline/inline.h"
85 #include "vm/jit/ir/bytecode.h"
87 #include "vm/jit/loop/analyze.h"
88 #include "vm/jit/loop/graph.h"
89 #include "vm/jit/loop/loop.h"
91 #if defined(ENABLE_IFCONV)
92 # include "vm/jit/optimizing/ifconv.h"
95 #include "vm/jit/optimizing/reorder.h"
97 #if defined(ENABLE_PYTHON)
98 # include "vm/jit/python.h"
101 #include "vm/jit/verify/typecheck.h"
104 /* debug macros ***************************************************************/
107 #define DEBUG_JIT_COMPILEVERBOSE(x) \
109 if (compileverbose) { \
110 log_message_method(x, m); \
114 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
118 # define TRACECOMPILERCALLS() \
120 if (opt_TraceCompilerCalls) { \
122 log_print("[JIT compiler started: method="); \
129 # define TRACECOMPILERCALLS()
133 /* the ICMD table ************************************************************/
136 #define N(name) name,
141 /* abbreviations for flags */
143 #define PEI ICMDTABLE_PEI
144 #define CALLS ICMDTABLE_CALLS
146 /* some machine dependent values */
151 #define IDIV_CALLS ICMDTABLE_CALLS
154 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
157 #define LDIV_CALLS ICMDTABLE_CALLS
160 /* include the actual table */
162 icmdtable_entry_t icmd_table[256] = {
163 #include <vm/jit/icmdtable.inc>
170 /* XXX hack until the old "PEI" definition is removed */
174 /* jit_init ********************************************************************
176 Initializes the JIT subsystem.
178 *******************************************************************************/
182 TRACESUBSYSTEMINITIALIZATION("jit_init");
184 #if defined(ENABLE_JIT)
185 /* initialize stack analysis subsystem */
190 /* initialize show subsystem */
196 /* initialize codegen subsystem */
200 /* initialize code subsystem */
204 /* Machine dependent initialization. */
206 #if defined(ENABLE_JIT)
207 # if defined(ENABLE_INTRP)
217 #if defined(ENABLE_OPAGENT)
218 if (opt_EnableOpagent)
219 OprofileAgent_initialize();
224 /* jit_close *******************************************************************
226 Close the JIT subsystem.
228 *******************************************************************************/
232 #if defined(ENABLE_OPAGENT)
233 if (opt_EnableOpagent)
234 OprofileAgent_close();
239 /* dummy function, used when there is no JavaVM code available */
241 static u1 *do_nothing_function(void)
247 /* jit_jitdata_new *************************************************************
249 Allocates and initalizes a new jitdata structure.
251 *******************************************************************************/
253 jitdata *jit_jitdata_new(methodinfo *m)
258 /* allocate jitdata structure and fill it */
263 jd->cd = DNEW(codegendata);
264 jd->rd = DNEW(registerdata);
265 #if defined(ENABLE_LOOP)
266 jd->ld = DNEW(loopdata);
269 /* Allocate codeinfo memory from the heap as we need to keep them. */
271 code = code_codeinfo_new(m);
273 /* Set codeinfo flags. */
275 #if defined(ENABLE_THREADS)
276 if (checksync && (m->flags & ACC_SYNCHRONIZED))
277 code_flag_synchronized(code);
279 if (checksync && (m->flags & ACC_SYNCHRONIZED))
280 code_unflag_leafmethod(code);
283 code_flag_leafmethod(code);
285 /* initialize variables */
289 jd->exceptiontable = NULL;
290 jd->exceptiontablelength = 0;
292 jd->branchtoentry = false;
293 jd->branchtoend = false;
295 jd->returnblock = NULL;
296 jd->maxlocals = m->maxlocals;
302 /* jit_compile *****************************************************************
304 Translates one method to machine code.
306 *******************************************************************************/
308 static u1 *jit_compile_intern(jitdata *jd);
310 u1 *jit_compile(methodinfo *m)
316 STATISTICS(count_jit_calls++);
318 /* Initialize the static function's class. */
320 /* ATTENTION: This MUST be done before the method lock is aquired,
321 otherwise we could run into a deadlock with <clinit>'s that
322 call static methods of it's own class. */
324 if ((m->flags & ACC_STATIC) && !(m->clazz->state & CLASS_INITIALIZED)) {
327 log_message_class("Initialize class ", m->clazz);
330 if (!initialize_class(m->clazz))
333 /* check if the method has been compiled during initialization */
335 if ((m->code != NULL) && (m->code->entrypoint != NULL))
336 return m->code->entrypoint;
339 /* enter a monitor on the method */
341 LOCK_MONITOR_ENTER(m);
343 /* if method has been already compiled return immediately */
345 if (m->code != NULL) {
346 LOCK_MONITOR_EXIT(m);
348 assert(m->code->entrypoint);
349 return m->code->entrypoint;
352 TRACECOMPILERCALLS();
354 STATISTICS(count_methods++);
356 #if defined(ENABLE_STATISTICS)
359 if (opt_getcompilingtime)
360 compilingtime_start();
363 /* mark start of dump memory area */
367 /* create jitdata structure */
369 jd = jit_jitdata_new(m);
371 /* set the flags for the current JIT run */
373 jd->flags = JITDATA_FLAG_PARSE;
375 #if defined(ENABLE_VERIFIER)
377 jd->flags |= JITDATA_FLAG_VERIFY;
380 #if defined(ENABLE_PROFILING)
382 jd->flags |= JITDATA_FLAG_INSTRUMENT;
385 #if defined(ENABLE_IFCONV)
387 jd->flags |= JITDATA_FLAG_IFCONV;
390 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
391 if (opt_Inline && opt_InlineAll)
392 jd->flags |= JITDATA_FLAG_INLINE;
395 if (opt_showintermediate)
396 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
398 if (opt_showdisassemble)
399 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
402 jd->flags |= JITDATA_FLAG_VERBOSECALL;
404 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
405 if (opt_Inline && (jd->m->hitcountdown > 0) && (jd->code->optlevel == 0)) {
406 jd->flags |= JITDATA_FLAG_COUNTDOWN;
410 #if defined(ENABLE_JIT)
411 # if defined(ENABLE_INTRP)
414 /* initialize the register allocator */
420 /* setup the codegendata memory */
424 /* now call internal compile function */
426 r = jit_compile_intern(jd);
429 /* We had an exception! Finish stuff here if necessary. */
431 /* release codeinfo */
433 code_codeinfo_free(jd->code);
435 #if defined(ENABLE_PROFILING)
436 /* Release memory for basic block profiling information. */
438 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
439 if (jd->code->bbfrequency != NULL)
440 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
444 DEBUG_JIT_COMPILEVERBOSE("Running: ");
447 /* release dump area */
451 #if defined(ENABLE_STATISTICS)
454 if (opt_getcompilingtime)
455 compilingtime_stop();
458 #if defined(ENABLE_OPAGENT)
459 if (opt_EnableOpagent)
460 OprofileAgent_newmethod(m);
463 /* leave the monitor */
465 LOCK_MONITOR_EXIT(m);
467 /* return pointer to the methods entry point */
473 /* jit_recompile ***************************************************************
475 Recompiles a Java method.
477 *******************************************************************************/
479 u1 *jit_recompile(methodinfo *m)
486 /* check for max. optimization level */
488 optlevel = (m->code) ? m->code->optlevel : 0;
492 /* log_message_method("not recompiling: ", m); */
497 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
499 STATISTICS(count_jit_calls++);
501 #if defined(ENABLE_STATISTICS)
504 if (opt_getcompilingtime)
505 compilingtime_start();
508 /* mark start of dump memory area */
512 /* create jitdata structure */
514 jd = jit_jitdata_new(m);
516 /* set the current optimization level to the previous one plus 1 */
518 jd->code->optlevel = optlevel + 1;
520 /* get the optimization flags for the current JIT run */
522 #if defined(ENABLE_VERIFIER)
523 jd->flags |= JITDATA_FLAG_VERIFY;
526 /* jd->flags |= JITDATA_FLAG_REORDER; */
527 if (opt_showintermediate)
528 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
529 if (opt_showdisassemble)
530 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
532 jd->flags |= JITDATA_FLAG_VERBOSECALL;
534 #if defined(ENABLE_INLINING)
536 jd->flags |= JITDATA_FLAG_INLINE;
539 #if defined(ENABLE_JIT)
540 # if defined(ENABLE_INTRP)
543 /* initialize the register allocator */
548 /* setup the codegendata memory */
552 /* now call internal compile function */
554 r = jit_compile_intern(jd);
557 /* We had an exception! Finish stuff here if necessary. */
559 /* release codeinfo */
561 code_codeinfo_free(jd->code);
564 /* release dump area */
568 #if defined(ENABLE_STATISTICS)
571 if (opt_getcompilingtime)
572 compilingtime_stop();
575 #if defined(ENABLE_OPAGENT)
576 if (opt_EnableOpagent)
577 OprofileAgent_newmethod(m);
580 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
582 /* return pointer to the methods entry point */
587 #if defined(ENABLE_PM_HACKS)
588 #include "vm/jit/jit_pm_1.inc"
591 /* jit_compile_intern **********************************************************
593 Static internal function which does the actual compilation.
595 *******************************************************************************/
597 static u1 *jit_compile_intern(jitdata *jd)
603 #if defined(ENABLE_RT_TIMING)
604 struct timespec time_start,time_checks,time_parse,time_stack,
605 time_typecheck,time_loop,time_ifconv,time_alloc,
609 RT_TIMING_GET_TIME(time_start);
611 /* get required compiler data */
613 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
620 #if defined(ENABLE_DEBUG_FILTER)
621 show_filters_apply(jd->m);
624 /* Handle native methods and create a native stub. */
626 if (m->flags & ACC_NATIVE) {
629 f = native_method_resolve(m);
634 code = codegen_generate_stub_native(m, f);
636 /* Native methods are never recompiled. */
642 return code->entrypoint;
645 /* if there is no javacode, print error message and return empty method */
647 if (m->jcode == NULL) {
648 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
650 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
653 return code->entrypoint; /* return empty method */
656 #if defined(ENABLE_STATISTICS)
658 count_javacodesize += m->jcodelength + 18;
659 count_tryblocks += jd->exceptiontablelength;
660 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
664 RT_TIMING_GET_TIME(time_checks);
666 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
667 /* Code for Sun's OpenJDK (see
668 hotspot/src/share/vm/classfile/verifier.cpp
669 (Verifier::is_eligible_for_verification)): Don't verify
670 dynamically-generated bytecodes. */
672 # if defined(ENABLE_VERIFIER)
673 if (class_issubclass(m->clazz, class_sun_reflect_MagicAccessorImpl))
674 jd->flags &= ~JITDATA_FLAG_VERIFY;
678 /* call the compiler passes ***********************************************/
680 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
682 /* call parse pass */
685 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
689 RT_TIMING_GET_TIME(time_parse);
691 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
693 #if defined(ENABLE_JIT)
694 # if defined(ENABLE_INTRP)
697 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
699 /* call stack analysis pass */
701 if (!stack_analyse(jd)) {
702 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
706 RT_TIMING_GET_TIME(time_stack);
708 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
710 #ifdef ENABLE_VERIFIER
711 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
712 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
714 /* call typecheck pass */
715 if (!typecheck(jd)) {
716 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
721 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
724 RT_TIMING_GET_TIME(time_typecheck);
726 #if defined(ENABLE_LOOP)
731 jit_renumber_basicblocks(jd);
734 RT_TIMING_GET_TIME(time_loop);
736 #if defined(ENABLE_IFCONV)
737 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
738 if (!ifconv_static(jd))
740 jit_renumber_basicblocks(jd);
743 RT_TIMING_GET_TIME(time_ifconv);
747 #if defined(ENABLE_INLINING) && (!defined(ENABLE_ESCAPE) || 1)
748 if (JITDATA_HAS_FLAG_INLINE(jd)) {
749 if (!inline_inline(jd))
754 #if defined(ENABLE_SSA)
756 fix_exception_handlers(jd);
760 /* Build the CFG. This has to be done after stack_analyse, as
761 there happens the JSR elimination. */
766 #if defined(ENABLE_PROFILING)
767 /* Basic block reordering. I think this should be done after
768 if-conversion, as we could lose the ability to do the
771 if (JITDATA_HAS_FLAG_REORDER(jd)) {
774 jit_renumber_basicblocks(jd);
778 #if defined(ENABLE_PM_HACKS)
779 #include "vm/jit/jit_pm_2.inc"
781 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
783 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
784 /* allocate registers */
789 STATISTICS(count_methods_allocated_by_lsra++);
792 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
793 #if defined(ENABLE_SSA)
794 /* allocate registers */
797 jd->code->optlevel > 0)
798 /* strncmp(jd->m->name->text, "hottie", 6) == 0*/
799 /*&& jd->exceptiontablelength == 0*/
801 /*printf("=== %s ===\n", jd->m->name->text);*/
802 jd->ls = DNEW(lsradata);
805 /*lsra(jd);*/ regalloc(jd);
806 /*eliminate_subbasicblocks(jd);*/
807 STATISTICS(count_methods_allocated_by_lsra++);
810 # endif /* defined(ENABLE_SSA) */
812 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
817 STATISTICS(simplereg_make_statistics(jd));
819 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
820 # if defined(ENABLE_INTRP)
823 #endif /* defined(ENABLE_JIT) */
824 RT_TIMING_GET_TIME(time_alloc);
826 #if defined(ENABLE_PROFILING)
827 /* Allocate memory for basic block profiling information. This
828 _must_ be done after loop optimization and register allocation,
829 since they can change the basic block count. */
831 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
832 code->bbfrequency = MNEW(u4, jd->basicblockcount);
835 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
837 /* now generate the machine code */
839 #if defined(ENABLE_JIT)
840 # if defined(ENABLE_INTRP)
842 #if defined(ENABLE_VERIFIER)
844 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
846 if (!typecheck_stackbased(jd)) {
847 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
852 if (!intrp_codegen(jd)) {
853 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
860 if (!codegen_generate(jd)) {
861 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
867 if (!intrp_codegen(jd)) {
868 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
873 RT_TIMING_GET_TIME(time_codegen);
875 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
877 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
878 /* activate replacement points inside newly created code */
880 if (opt_TestReplacement)
881 replace_activate_replacement_points(code, false);
885 #if defined(ENABLE_DEBUG_FILTER)
886 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
889 /* intermediate and assembly code listings */
891 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
892 show_method(jd, SHOW_CODE);
894 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
895 # if defined(ENABLE_DISASSEMBLER)
896 DISASSEMBLE(code->entrypoint,
897 code->entrypoint + (code->mcodelength - cd->dseglen));
901 if (opt_showddatasegment)
906 /* switch to the newly generated code */
909 assert(code->entrypoint);
911 /* add the current compile version to the methodinfo */
913 code->prev = m->code;
916 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
917 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
918 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
919 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
920 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
921 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
922 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
923 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
925 /* return pointer to the methods entry point */
927 return code->entrypoint;
931 /* jit_invalidate_code *********************************************************
933 Mark the compiled code of the given method as invalid and take care that
934 it is replaced if necessary.
936 XXX Not fully implemented, yet.
938 *******************************************************************************/
940 void jit_invalidate_code(methodinfo *m)
946 if (code == NULL || code_is_invalid(code))
949 code_flag_invalid(code);
951 /* activate mappable replacement points */
953 #if defined(ENABLE_REPLACEMENT)
954 replace_activate_replacement_points(code, true);
956 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
961 /* jit_request_optimization ****************************************************
963 Request optimization of the given method. If the code of the method is
964 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
965 triggers an optimized recompilation.
966 If the method is already optimized, this function does nothing.
969 m................the method
971 *******************************************************************************/
973 void jit_request_optimization(methodinfo *m)
979 if (code && code->optlevel == 0)
980 jit_invalidate_code(m);
984 /* jit_get_current_code ********************************************************
986 Get the currently valid code for the given method. If there is no valid
987 code, (re)compile the method.
990 m................the method
993 the codeinfo* for the current code, or
994 NULL if an exception has been thrown during recompilation.
996 *******************************************************************************/
998 codeinfo *jit_get_current_code(methodinfo *m)
1002 /* if we have valid code, return it */
1004 if (m->code && !code_is_invalid(m->code))
1007 /* otherwise: recompile */
1009 if (!jit_recompile(m))
1018 /* jit_asm_compile *************************************************************
1020 This method is called from asm_vm_call_method and does:
1022 - create stackframe info for exceptions
1023 - compile the method
1024 - patch the entrypoint of the method into the calculated address in
1026 - flushes the instruction cache.
1028 *******************************************************************************/
1030 #if defined(ENABLE_JIT)
1031 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1032 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1034 stackframeinfo_t sfi;
1039 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1040 /* instruction after the call) */
1042 stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1044 /* actually compile the method */
1046 entrypoint = jit_compile(m);
1048 /* remove the stackframeinfo */
1050 stacktrace_stackframeinfo_remove(&sfi);
1052 /* there was a problem during compilation */
1054 if (entrypoint == NULL)
1057 /* get the method patch address */
1059 pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1061 /* patch the method entry point */
1065 *p = (ptrint) entrypoint;
1067 /* flush the instruction cache */
1069 md_icacheflush(pa, SIZEOF_VOID_P);
1075 /* jit_compile_handle **********************************************************
1077 This method is called from the appropriate signal handler which
1078 handles compiler-traps and does the following:
1080 - compile the method
1081 - patch the entrypoint of the method into the calculated address in
1083 - flush the instruction cache
1085 *******************************************************************************/
1087 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1089 void *newpv; /* new compiled method PV */
1090 void *pa; /* patch address */
1091 uintptr_t *p; /* convenience pointer */
1093 /* Compile the method. */
1095 newpv = jit_compile(m);
1097 /* There was a problem during compilation. */
1102 /* Get the method patch address. */
1104 pa = md_jit_method_patch_address(pv, ra, mptr);
1106 /* Patch the method entry point. */
1108 p = (uintptr_t *) pa;
1110 *p = (uintptr_t) newpv;
1112 /* Flush both caches. */
1114 md_cacheflush(pa, SIZEOF_VOID_P);
1118 #endif /* defined(ENABLE_JIT) */
1121 /* jit_complement_condition ****************************************************
1123 Returns the complement of the passed conditional instruction.
1125 We use the order of the different conditions, e.g.:
1130 If the passed opcode is odd, we simply add 1 to get the complement.
1131 If the opcode is even, we subtract 1.
1138 *******************************************************************************/
1140 s4 jit_complement_condition(s4 opcode)
1144 return ICMD_IFNONNULL;
1146 case ICMD_IFNONNULL:
1150 /* check if opcode is odd */
1160 /* jit_renumber_basicblocks ****************************************************
1162 Set the ->nr of all blocks so it increases when traversing ->next.
1165 jitdata..........the current jitdata
1167 *******************************************************************************/
1169 void jit_renumber_basicblocks(jitdata *jd)
1175 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1179 /* we have one block more than jd->basicblockcount (the end marker) */
1181 assert(nr == jd->basicblockcount + 1);
1185 /* jit_check_basicblock_numbers ************************************************
1187 Assert that the ->nr of the first block is zero and increases by 1 each
1188 time ->next is traversed.
1189 This function should be called before any analysis that relies on
1190 the basicblock numbers.
1193 jitdata..........the current jitdata
1195 NOTE: Aborts with an assertion if the condition is not met!
1197 *******************************************************************************/
1199 #if !defined(NDEBUG)
1200 void jit_check_basicblock_numbers(jitdata *jd)
1206 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1207 assert(bptr->nr == nr);
1211 /* we have one block more than jd->basicblockcount (the end marker) */
1213 assert(nr == jd->basicblockcount + 1);
1215 #endif /* !defined(NDEBUG) */
1217 methoddesc *instruction_call_site(const instruction *iptr) {
1218 if (iptr->opc == ICMD_BUILTIN) {
1219 return iptr->sx.s23.s3.bte->md;
1220 } else if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1221 return iptr->sx.s23.s3.um->methodref->parseddesc.md;
1223 return iptr->sx.s23.s3.fmiref->p.method->parseddesc;
1228 * These are local overrides for various environment variables in Emacs.
1229 * Please do not remove this and leave it at the end of the file, where
1230 * Emacs will automagically detect them.
1231 * ---------------------------------------------------------------------
1234 * indent-tabs-mode: t
1238 * vim:noexpandtab:sw=4:ts=4: