⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icode.c

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 C
📖 第 1 页 / 共 5 页
字号:
/* icode.c * Define the instructions. * * Copyright (c) 1996, 1997 *	Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution  * of this file.  */#include "config.h"#include "config-std.h"#include "config-mem.h"#include "gtypes.h"#include "kaffe/jmalloc.h"#include "slots.h"#include "seq.h"#include "registers.h"#include "basecode.h"#include "labels.h"#include "constpool.h"#include "icode.h"#include "soft.h"#include "access.h"#include "object.h"#include "constants.h"#include "classMethod.h"#include "gc.h"#include "support.h"#include "stats.h"#include "itypes.h"#include "md.h"#include "locks.h"#include "machine.h"#include "codeproto.h"#include "fp.h"#if defined(WORDS_BIGENDIAN)#define	LSLOT(_s)	((_s)+1)#define	HSLOT(_s)	(_s)#else#define	LSLOT(_s)	(_s)#define	HSLOT(_s)	((_s)+1)#endifvoid startBlock(sequence*);void endBlock(sequence*);void startSubBlock(sequence*);void endSubBlock(sequence*);void prepareFunctionCall(sequence*);void fixupFunctionCall(sequence*);void syncRegisters(sequence*);void nowritebackSlot(sequence*);bool used_ieee_rounding;bool used_ieee_division;#define	MAXLABTAB	64label* labtab[MAXLABTAB];/* ----------------------------------------------------------------------- *//* Register loads and spills.						   *//*									   */#if defined(HAVE_spill_int)voidspill_int(SlotInfo* src){	void HAVE_spill_int(sequence*);	sequence s;	seq_dst(&s) = src;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(src);	HAVE_spill_int(&s);}#endif#if defined(HAVE_reload_int)voidreload_int(SlotInfo* dst){	void HAVE_reload_int(sequence*);	sequence s;	seq_dst(&s) = dst;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(dst);	HAVE_reload_int(&s);}#endif#if defined(HAVE_spill_ref)voidspill_ref(SlotInfo* src){	void HAVE_spill_ref(sequence*);	sequence s;	seq_dst(&s) = src;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(src);	HAVE_spill_ref(&s);}#endif#if defined(HAVE_reload_ref)voidreload_ref(SlotInfo* dst){	void HAVE_reload_ref(sequence*);	sequence s;	seq_dst(&s) = dst;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(dst);	HAVE_reload_ref(&s);}#endif#if defined(HAVE_spill_long)voidspill_long(SlotInfo* src){	void HAVE_spill_long(sequence*);	sequence s;	seq_dst(&s) = src;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(src);	HAVE_spill_long(&s);}#endif#if defined(HAVE_reload_long)voidreload_long(SlotInfo* dst){	void HAVE_reload_long(sequence*);	sequence s;	seq_dst(&s) = dst;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(dst);	HAVE_reload_long(&s);}#endif#if defined(HAVE_spill_float)voidspill_float(SlotInfo* src){	void HAVE_spill_float(sequence*);	sequence s;	seq_dst(&s) = src;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(src);	HAVE_spill_float(&s);}#endif#if defined(HAVE_reload_float)voidreload_float(SlotInfo* dst){	void HAVE_reload_float(sequence*);	sequence s;	seq_dst(&s) = dst;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(dst);	HAVE_reload_float(&s);}#endif#if defined(HAVE_spill_double)voidspill_double(SlotInfo* src){	void HAVE_spill_double(sequence*);	sequence s;	seq_dst(&s) = src;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(src);	HAVE_spill_double(&s);}#endif#if defined(HAVE_reload_double)voidreload_double(SlotInfo* dst){	void HAVE_reload_double(sequence*);	sequence s;	seq_dst(&s) = dst;	seq_value(&s, 1) = SLOT2FRAMEOFFSET(dst);	HAVE_reload_double(&s);}#endif/* ----------------------------------------------------------------------- *//* Prologues and epilogues.						   *//*									   */voidprologue(Method* meth){	label* l;	used_ieee_rounding = false;	used_ieee_division = false;	l = KaffeJIT_newLabel();	l->type = Lnull;	l->at = 0;	l->to = 0;	l->from = 0;	/* Emit prologue code */	slot_const_const(NULL, (jword)l, (jword)meth, HAVE_prologue, Tnull);#if defined(ENABLE_JVMPI)	{		SlotInfo *tmp;		slot_alloctmp(tmp);		if( METHOD_IS_STATIC(meth) )			move_ref_const(tmp, NULL);		else			move_ref(tmp, local(0));		softcall_enter_method(tmp, meth);		slot_freetmp(tmp);	}#endif}voidexception_prologue(void){	label* l;	l = KaffeJIT_newLabel();	l->type = Lnull;	l->at = 0;	l->to = 0;	l->from = 0;	/* Emit exception prologue code */	slot_const_const(NULL, (jword)l, 0, HAVE_exception_prologue, Tnull);}voidepilogue(void){	slot_slot_slot(NULL, NULL, NULL, HAVE_epilogue, Tnull);}voidexit_method(void){#if defined(ENABLE_JVMPI)	softcall_exit_method(globalMethod);#endif}voidret(void){	label *l;		l = KaffeJIT_newLabel();	l->at = 0;	l->to = 0;	l->from = 0;	/* Jump to epilogue */	l->type = Lepilogue;	branch (l, ba);}/* ----------------------------------------------------------------------- *//* Conditional monitor management.					   *//*									   */voidmon_enter(methods* meth, SlotInfo* obj){	/* Emit monitor entry if required */	end_sub_block();	if ((meth->accflags & ACC_STATIC) != 0) {		pusharg_class_const(meth->class, 0);	}	else {		pusharg_ref(obj, 0);	}	call_soft(lockObject);	popargs();	start_sub_block();}voidmon_exit(methods* meth, SlotInfo* obj){	end_sub_block();	if ((meth->accflags & ACC_STATIC) != 0) {		pusharg_class_const(meth->class, 0);	}	else {		pusharg_ref(obj, 0);	}	call_soft(unlockObject);	popargs();	start_sub_block();}/* ----------------------------------------------------------------------- *//* Basic block and instruction management.				   *//*									   */void_start_basic_block(void){	int i;	_slot_const_const(NULL, 0, 0, startBlock, Tnull);	for (i = maxslot - 1; i >= 0; i--) {		slotinfo[i].info = SI_SLOT;	}}void_end_basic_block(uintp stk, uintp temp){	_slot_const_const(NULL, stk, temp, endBlock, Tnull);}void_start_sub_block(void){	_slot_const_const(NULL, 0, 0, startSubBlock, Tnull);}void_end_sub_block(uintp stk, uintp temp){	_slot_const_const(NULL, stk, temp, endSubBlock, Tnull);}void_start_instruction(uintp pc){	void startInsn(sequence*);	_slot_const_const(NULL, 0, pc, startInsn, Tnull);}void_start_exception_block(uintp stk){	/* Exception blocks act like function returns - the return	 * value is the exception object.	 */	start_basic_block();	exception_prologue();	return_ref(&localinfo[stk]);}void_fixup_function_call(void){	_slot_const_const(NULL, 0, 0, fixupFunctionCall, Tnull);}void_prepare_function_call(uintp stk, uintp temp){	_slot_const_const(NULL, stk, temp, prepareFunctionCall, Tnull);}void_slot_nowriteback(SlotInfo* slt){	_slot_const_const(slt, 0, 0, nowritebackSlot, Tnull);}void _syncRegisters(uintp stk, uintp temp){	_slot_const_const(NULL, stk, temp, syncRegisters, Tnull);}/* ----------------------------------------------------------------------- *//* Moves.								   *//*									   */voidmove_int_const(SlotInfo* dst, jint val){#if defined(HAVE_move_int_const)	if (HAVE_move_int_const_rangecheck(val)) {		slot_slot_const(dst, NULL, val, HAVE_move_int_const, Tconst);	}	else#endif	{		constpool *c;		label* l;		SlotInfo* tmp;		c = KaffeJIT_newConstant(CPint, val);		l = KaffeJIT_newLabel();		l->type = Lconstant;		l->at = 0;		l->to = (uintp)c;		l->from = 0;		slot_alloctmp(tmp);		move_label_const(tmp, l);		load_int(dst, tmp);		slot_freetmp(tmp);	}}voidmove_ref_const(SlotInfo* dst, void *val){#if defined(HAVE_move_ref_const)	if (HAVE_move_ref_const_rangecheck(val)) {		slot_slot_const(dst, NULL, (jword)val, HAVE_move_ref_const, Tconst);	}	else#endif	{		constpool *c;		label* l;		SlotInfo* tmp;		c = KaffeJIT_newConstant(CPref, val);		l = KaffeJIT_newLabel();		l->type = Lconstant;		l->at = 0;		l->to = (uintp)c;		l->from = 0;		slot_alloctmp(tmp);		move_label_const(tmp, l);		load_ref(dst, tmp);		slot_freetmp(tmp);	}}voidmove_string_const(SlotInfo* dst, void *val){#if 1	move_ref_const(dst, val);#else	label* l;	constpool *c;	SlotInfo* tmp;	c = KaffeJIT_newConstant(CPstring, val);	l = KaffeJIT_newLabel();	l->type = Lconstant;	l->at = 0;	l->to = (uintp)c;	l->from = 0;	slot_alloctmp(tmp);	move_label_const(tmp, l);	load_ref(dst, tmp);	slot_freetmp(tmp);#endif}voidmove_long_const(SlotInfo* dst, jlong val){#if defined(HAVE_move_long_const)	if (HAVE_move_long_const_rangecheck(val)) {		lslot_slot_lconst(dst, 0, val, HAVE_move_long_const, Tconst);	}	else {		constpool *c;		label* l;		SlotInfo* tmp;		c = KaffeJIT_newConstant(CPlong, val);		l = KaffeJIT_newLabel();		l->type = Lconstant;		l->at = 0;		l->to = (uintp)c;		l->from = 0;		slot_alloctmp(tmp);		move_label_const(tmp, l);		load_long(dst, tmp);		slot_freetmp(tmp);	}#else	move_int_const(LSLOT(dst), (jint)(val & 0xFFFFFFFF));	move_int_const(HSLOT(dst), (jint)((val >> 32) & 0xFFFFFFFF));#endif}voidmove_float_const(SlotInfo* dst, float val){#if defined(HAVE_move_float_const)	if (HAVE_move_float_const_rangecheck(val)) {		slot_slot_fconst(dst, NULL, val, HAVE_move_float_const, Tconst);	}	else#endif	{		constpool *c;		label* l;		SlotInfo* tmp;		c = KaffeJIT_newConstant(CPfloat, val);		l = KaffeJIT_newLabel();		l->type = Lconstant;		l->at = 0;		l->to = (uintp)c;		l->from = 0;		slot_alloctmp(tmp);		move_label_const(tmp, l);		load_float(dst, tmp);		slot_freetmp(tmp);	}}voidmove_double_const(SlotInfo* dst, jdouble val){#if defined(HAVE_move_double_const)	if (HAVE_move_double_const_rangecheck(val)) {		lslot_slot_fconst(dst, NULL, val, HAVE_move_double_const, Tconst);	}	else#endif	{		constpool *c;		label* l;		SlotInfo* tmp;		c = KaffeJIT_newConstant(CPdouble, val);		l = KaffeJIT_newLabel();		l->type = Lconstant;		l->at = 0;		l->to = (uintp)c;		l->from = 0;		slot_alloctmp(tmp);		move_label_const(tmp, l);		load_double(dst, tmp);		slot_freetmp(tmp);	}}#if defined(HAVE_move_any)voidmove_any(SlotInfo* dst, SlotInfo* src){	slot_slot_slot(dst, NULL, src, HAVE_move_any, Tcopy);}#endif#if defined(HAVE_move_int)voidmove_int(SlotInfo* dst, SlotInfo* src){	slot_slot_slot(dst, NULL, src, HAVE_move_int, Tcopy);}#endifvoidmove_ref(SlotInfo* dst, SlotInfo* src){	slot_slot_slot(dst, NULL, src, HAVE_move_ref, Tcopy);}voidmove_anylong(SlotInfo* dst, SlotInfo* src){#if defined(HAVE_move_anylong)	lslot_lslot_lslot(dst, NULL, src, HAVE_move_anylong, Tcopy);#else	assert(LSLOT(dst) != HSLOT(src));	move_any(LSLOT(dst), LSLOT(src));	move_any(HSLOT(dst), HSLOT(src));#endif}voidmove_long(SlotInfo* dst, SlotInfo* src){#if defined(HAVE_move_long)	lslot_lslot_lslot(dst, NULL, src, HAVE_move_long, Tcopy);#else	assert(LSLOT(dst) != HSLOT(src));	move_int(LSLOT(dst), LSLOT(src));	move_int(HSLOT(dst), HSLOT(src));#endif}#if defined(HAVE_move_float)voidmove_float(SlotInfo* dst, SlotInfo* src){	slot_slot_slot(dst, NULL, src, HAVE_move_float, Tcopy);}#endif#if defined(HAVE_move_double)voidmove_double(SlotInfo* dst, SlotInfo* src){	lslot_lslot_lslot(dst, NULL, src, HAVE_move_double, Tcopy);}#endif#if defined(HAVE_move_label_const)voidmove_label_const(SlotInfo* dst, label* lab){	slot_slot_const(dst, NULL, (jword)lab, HAVE_move_label_const, Tnull);}#endifvoidswap_any(SlotInfo* src, SlotInfo* src2){#if defined(HAVE_swap_any)	slot_slot_slot(src, 0, src2, HAVE_swap_any, Tcomplex);#else	SlotInfo* tmp;	slot_alloctmp(tmp);	move_ref(tmp, src);	move_ref(src, src2);	move_ref(src2, tmp);	slot_freetmp(tmp);#endif}/* ----------------------------------------------------------------------- *//* Arithmetic operators - add, sub, etc.				   *//*									   */#if defined(HAVE_adc_int)voidadc_int(SlotInfo* dst, SlotInfo* src, SlotInfo* src2){	slot_slot_slot(dst, src, src2, HAVE_adc_int, Tcomplex);}#endifvoidadd_int_const(SlotInfo* dst, SlotInfo* src, jint val){#if defined(HAVE_add_int_const)	if (HAVE_add_int_const_rangecheck(val)) {		slot_slot_const(dst, src, val, HAVE_add_int_const, Tcomplex);	}	else#endif	{		SlotInfo* tmp;		slot_alloctmp(tmp);		move_int_const(tmp, val);		add_int(dst, src, tmp);		slot_freetmp(tmp);	}}#if defined(HAVE_add_int)voidadd_int(SlotInfo* dst, SlotInfo* src, SlotInfo* src2){	slot_slot_slot(dst, src, src2, HAVE_add_int, Tcomm);}#endif#if defined(HAVE_add_ref)voidadd_ref(SlotInfo* dst, SlotInfo* src, SlotInfo* src2){	slot_slot_slot(dst, src, src2, HAVE_add_ref, Tcomm);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -