/*
 * Handle a label.
 */
static void JITCoder_Label(ILCoder *coder, ILUInt32 offset)
{
	ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
	ILJITLabel *label = _ILJitLabelGet(jitCoder, offset, _IL_JIT_LABEL_NORMAL);

	if(label)
	{
		_ILJitValuesResetNullChecked(jitCoder);
		if(label->labelType == _IL_JIT_LABEL_STARTFINALLY)
		{
		#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
			if (jitCoder->flags & IL_CODER_FLAG_STATS)
			{
				ILMutexLock(globalTraceMutex);
				fprintf(stdout,
					"StartFinally: %i\n", 
					offset);
				ILMutexUnlock(globalTraceMutex);
			}
		#endif
			jit_insn_start_finally(jitCoder->jitFunction, &(label->label));
		}
		else
		{
		#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
			if (jitCoder->flags & IL_CODER_FLAG_STATS)
			{
				ILMutexLock(globalTraceMutex);
				fprintf(stdout,
					"Label: %i\n", 
					offset);
				ILMutexUnlock(globalTraceMutex);
			}
		#endif
			_ILJitLabelRestoreStack(jitCoder, label);
			jit_insn_label(jitCoder->jitFunction, &(label->label));
		}
	}
}
Beispiel #2
0
/*
 * Inline function to get the character at the specified indexe in a
 * string.
 */
static int _ILJitSystemStringChars(ILJITCoder *jitCoder,
								   ILMethod *method,
								   ILCoderMethodInfo *methodInfo,
								   ILJitStackItem *args,
								   ILInt32 numArgs)
{
	ILJitFunction jitFunction = ILJitFunctionFromILMethod(method);
	ILClass *stringClass = ILMethod_Owner(method);
	ILJitValue length;
	ILJitValue stringBase;
	ILJitValue returnValue;

	if(!jitFunction)
	{
		/* We need to layout the class first. */
		if(!_LayoutClass(ILExecThreadCurrent(), stringClass))
		{
			return 0;
		}
		if(!(jitFunction = ILJitFunctionFromILMethod(method)))
		{
			return 0;
		}
	}

#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) && defined(_IL_JIT_ENABLE_DEBUG)
	if(jitCoder->flags & IL_CODER_FLAG_STATS)
	{
		ILMutexLock(globalTraceMutex);
		fprintf(stdout, "Inline System.String::get_Chars\n");
		ILMutexUnlock(globalTraceMutex);
	}
#endif

	_ILJitStackItemCheckNull(jitCoder, args[0]);
	length = _ILJitStringGetLength(jitCoder->jitFunction,
								   _ILJitStackItemValue(args[0]));
	JITC_START_CHECK_STRING_INDEX(jitCoder, length, _ILJitStackItemValue(args[1]))
	stringBase = _ILJitStringGetStart(jitCoder->jitFunction,
									  _ILJitStackItemValue(args[0]));
	returnValue = jit_insn_load_elem(jitCoder->jitFunction,
									 stringBase,
									 _ILJitStackItemValue(args[1]),
									 _IL_JIT_TYPE_CHAR);
	JITC_END_CHECK_STRING_INDEX(jitCoder)

	_ILJitStackPushValue(jitCoder, returnValue);
	return 1;
}
/*
 * Output a branch instruction using a JIT coder.
 */
static void JITCoder_Branch(ILCoder *coder, int opcode, ILUInt32 dest,
				   		    ILEngineType type1, ILEngineType type2)
{
	ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
	ILJITLabel *label = 0;
	ILJitValue temp = 0;
	_ILJitStackItemNew(value2);
	_ILJitStackItemNew(value1);

#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
	if (jitCoder->flags & IL_CODER_FLAG_STATS)
	{
		ILMutexLock(globalTraceMutex);
		fprintf(stdout,
			"Branch: %i\n", 
			dest);
		ILMutexUnlock(globalTraceMutex);
	}
#endif
	/* Determine what form of branch to use */
	switch(opcode)
	{
		case IL_OP_BR:
		case IL_OP_BR_S:
		case IL_OP_LEAVE:
		case IL_OP_LEAVE_S:
		{
			/* Unconditional branch */
			label = _ILJitLabelGet(jitCoder, dest, _IL_JIT_LABEL_NORMAL);

			jit_insn_branch(jitCoder->jitFunction, &(label->label));
		}
		break;

		case IL_OP_BRTRUE_S:
		case IL_OP_BRTRUE:
		{
			/* Branch if the top-most stack item is true */
			_ILJitStackPop(jitCoder, value1);
			label = _ILJitLabelGet(jitCoder, dest, _IL_JIT_LABEL_NORMAL);

			jit_insn_branch_if(jitCoder->jitFunction,
							   _ILJitStackItemValue(value1),
							   &(label->label));
		}
		break;

		case IL_OP_BRFALSE_S:
		case IL_OP_BRFALSE:
		{
			/* Branch if the top-most stack item is false */
			_ILJitStackPop(jitCoder, value1);
			label = _ILJitLabelGet(jitCoder, dest, _IL_JIT_LABEL_NORMAL);

			jit_insn_branch_if_not(jitCoder->jitFunction,
								   _ILJitStackItemValue(value1),
								   &(label->label));
		}
		break;

		default:
		{
			_ILJitStackPop(jitCoder, value2);
			_ILJitStackPop(jitCoder, value1);
			label = _ILJitLabelGet(jitCoder, dest, _IL_JIT_LABEL_NORMAL);

			switch(opcode)
			{
				case IL_OP_BEQ:
				case IL_OP_BEQ_S:
				{
					/* Equality testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BEQ,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp, 
									   &(label->label));
				}
				break;

				case IL_OP_BNE_UN:
				case IL_OP_BNE_UN_S:
				{
					/* Unsigned inequality testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BNE_UN,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp, 
									   &(label->label));
				}
				break;

				case IL_OP_BGT:
				case IL_OP_BGT_S:
				{
					/* Signed greater than testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BGT,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BGT_UN:
				case IL_OP_BGT_UN_S:
				{
					/* Unsigned greater than testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BGT_UN,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BGE:
				case IL_OP_BGE_S:
				{
					/* Signed greater than or equal testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BGE,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BGE_UN:
				case IL_OP_BGE_UN_S:
				{
					/* Unsigned greater than or equal testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BGE_UN,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BLT:
				case IL_OP_BLT_S:
				{
					/* Signed less than testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BLT,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BLT_UN:
				case IL_OP_BLT_UN_S:
				{
					/* Unsigned less than testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BLT_UN,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BLE:
				case IL_OP_BLE_S:
				{
					/* Signed less than or equal testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BLE,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;

				case IL_OP_BLE_UN:
				case IL_OP_BLE_UN_S:
				{
					/* Unsigned less than or equal testing branch */
					temp = OutputCompare(jitCoder, IL_OP_BLE_UN,
										 &(_ILJitStackItemValue(value1)),
										 &(_ILJitStackItemValue(value2)));
					jit_insn_branch_if(jitCoder->jitFunction, temp,
									   &(label->label));
				}
				break;
			}
		}
		break;
	}

}
Beispiel #4
0
/*
 * Destroy the engine.
 */
void ILExecEngineDestroy(ILExecEngine *engine)
{
	int count;
	ILExecProcess *process;	
	ILQueueEntry *unloadQueue, *destroyQueue;
	
	unloadQueue = ILQueueCreate();
	destroyQueue = ILQueueCreate();

	/* Lock the engine process list*/
	ILMutexLock(engine->processLock);

	count = 0;

	/* Walk all the application domains and collect them */

	process = engine->firstProcess;

	while (process)
	{
		if (process != engine->defaultProcess)
		{
			if(process->state < _IL_PROCESS_STATE_UNLOADING)
			{
				ILQueueAdd(&unloadQueue, process);

			}
			ILQueueAdd(&destroyQueue, process);
			count++;
		}
		/* Move onto the next process */
		process = process->nextProcess;
	}

	/* Unlock the engine process list */
	ILMutexUnlock(engine->processLock);

	if ((!unloadQueue || !destroyQueue) && count != 0)
	{
		/* Probably ran out of memory trying to build the unload and destroy
			queue */
		return;
	}

	/* unload all processes */
	while (unloadQueue)
	{
		process = (ILExecProcess *)ILQueueRemove(&unloadQueue);
		ILExecProcessUnload(process);
	}

	/* now destroy the processes */
	while (destroyQueue)
	{
		process = (ILExecProcess *)ILQueueRemove(&destroyQueue);
		ILExecProcessDestroy(process);
	}
 
	/* now unload and destroy the default process */
	if(engine->defaultProcess)
	{
		ILExecProcessUnload(engine->defaultProcess);
		ILExecProcessDestroy(engine->defaultProcess);
	}

	if (engine->processLock)
	{
		/* Destroy the process list lock */
		ILMutexDestroy(engine->processLock);
	}

	/* Free the engine block itself */
	ILGCFreePersistent(engine);
}
Beispiel #5
0
/*
 * Inline function to create a new string with the given length 
 */
static int _ILJitSystemStringNew(ILJITCoder *jitCoder,
								 ILMethod *method,
								 ILCoderMethodInfo *methodInfo,
								 ILJitStackItem *args,
								 ILInt32 numArgs)
{
	ILJitFunction jitFunction = ILJitFunctionFromILMethod(method);
	ILClass *stringClass = ILMethod_Owner(method);
	ILJitValue newString;
	ILJitValue callArgs[2];

	if(!jitFunction)
	{
		/* We need to layout the class first. */
		if(!_LayoutClass(ILExecThreadCurrent(), stringClass))
		{
			return 0;
		}
		if(!(jitFunction = ILJitFunctionFromILMethod(method)))
		{
			return 0;
		}
	}

#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) && defined(_IL_JIT_ENABLE_DEBUG)
	if(jitCoder->flags & IL_CODER_FLAG_STATS)
	{
		ILMutexLock(globalTraceMutex);
		fprintf(stdout, "Inline System.String::NewString\n");
		ILMutexUnlock(globalTraceMutex);
	}
#endif

	/* We call the alloc functions. */
	/* They thow an out of memory exception so we don't need to care. */
	callArgs[0] = jit_value_create_nint_constant(jitCoder->jitFunction,
												 _IL_JIT_TYPE_VPTR,
												 (jit_nint)stringClass);
	if(!callArgs[0])
	{
		return 0;
	}
	callArgs[1] = _ILJitValueConvertImplicit(jitCoder->jitFunction,
						 					 _ILJitStackItemValue(args[0]),
											 _IL_JIT_TYPE_UINT32);
	if(!callArgs[1])
	{
		return 0;
	}
	newString = jit_insn_call_native(jitCoder->jitFunction,
									 "_ILJitStringAlloc",
									 _ILJitStringAlloc,
									 _ILJitSignature_ILJitStringAlloc,
				 					 callArgs, 2, 0);
	if(!newString)
	{
		return 0;
	}

	_ILJitStackPushValue(jitCoder, newString);
	return 1;
}