Index: vm/include/open/vm.h =================================================================== --- vm/include/open/vm.h (revision 523181) +++ vm/include/open/vm.h (working copy) @@ -655,7 +655,7 @@ * @return The current method of the iterator. NULL is returned if * therea are no more methods. */ -VMEXPORT Method_Handle method_iterator_get_current(ChaMethodIterator*); +VMEXPORT Method_Handle method_iterator_get_current(const ChaMethodIterator*); /** * Advances the iterator. Index: vm/include/jit_import.h =================================================================== --- vm/include/jit_import.h (revision 523181) +++ vm/include/jit_import.h (working copy) @@ -297,8 +297,9 @@ /** * The following values should be used as the "heat" argument for - * calls like method_allocate_code_block() or + * calls like * malloc_fixed_code_for_jit(). + * FIXME merge with CodeBlockHeat enumeration */ #define CODE_BLOCK_HEAT_COLD 0 @@ -313,6 +314,15 @@ CAA_Simulate, CAA_Allocate }Code_Allocation_Action; + +// +// Code block heat - used when a method is split into hot and cold parts +// +typedef enum { + CodeBlockHeatMin, + CodeBlockHeatDefault, + CodeBlockHeatMax +} CodeBlockHeat; /** @@ -336,7 +346,7 @@ JIT_Handle j, size_t size, size_t alignment, - unsigned heat, + CodeBlockHeat heat, int id, Code_Allocation_Action action); Index: vm/vmcore/src/class_support/C_Interface.cpp =================================================================== --- vm/vmcore/src/class_support/C_Interface.cpp (revision 523181) +++ vm/vmcore/src/class_support/C_Interface.cpp (working copy) @@ -288,22 +288,28 @@ JIT_Handle j, size_t size, size_t alignment, - unsigned heat, + CodeBlockHeat heat, int id, Code_Allocation_Action action) { Method *method = (Method *)m; assert(method); - Class_Handle UNUSED clss = method_get_class(method); - assert(clss); - JIT *jit = (JIT *)j; assert(jit); - Byte *code_block = NULL; + uint32 drlHeat; + if (heat == CodeBlockHeatMin) + drlHeat = CODE_BLOCK_HEAT_COLD; + else if (heat == CodeBlockHeatMax) + drlHeat = CODE_BLOCK_HEAT_MAX/2; + else { + assert (heat == CodeBlockHeatDefault); + drlHeat = CODE_BLOCK_HEAT_DEFAULT; + } + // the following method is safe to call from multiple threads - code_block = (Byte *) method->allocate_code_block_mt(size, alignment, jit, heat, id, action); + Byte *code_block = (Byte *) method->allocate_code_block_mt(size, alignment, jit, drlHeat, id, action); return code_block; } // method_allocate_code_block @@ -2570,7 +2576,7 @@ } // method_iterator_initialize -Method_Handle method_iterator_get_current(ChaMethodIterator *chaClassIterator) +Method_Handle method_iterator_get_current(const ChaMethodIterator *chaClassIterator) { return (chaClassIterator->_class_iter._is_valid ? chaClassIterator->_current : NULL); } // method_iterator_get_current Index: vm/jitrino/src/codegenerator/CodeGenIntfc.cpp =================================================================== --- vm/jitrino/src/codegenerator/CodeGenIntfc.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/CodeGenIntfc.cpp (working copy) @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author Intel, Vyacheslav P. Shakin - * @version $Revision: 1.16.16.5 $ - * - */ - -#include "CodeGenIntfc.h" -#if defined (_IPF_) - #include "IpfCodeGenerator.h" -#else - #include "ia32/Ia32CodeGenerator.h" -#endif - - -namespace Jitrino { - - -} - Index: vm/jitrino/src/codegenerator/ia32/Ia32GCMap.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32GCMap.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32GCMap.cpp (working copy) @@ -357,11 +357,11 @@ #endif } -void GCMap::checkObject(DrlVMTypeManager& tm, const void* p) { +void GCMap::checkObject(TypeManager& tm, const void* p) { if (p==NULL) return; m_assert (!(p<(const void*)0x10000)); //(INVALID PTR) m_assert((((POINTER_SIZE_INT)p)&0x3)==0); // check for valid alignment - POINTER_SIZE_INT vtableOffset=tm.getVTableOffset(); + POINTER_SIZE_INT vtableOffset = VMInterface::getVTableOffset(); void * allocationHandle=*(void**)(((uint8*)p)+vtableOffset); m_assert (!(allocationHandle<(void*)0x10000 || (((POINTER_SIZE_INT)allocationHandle)&0x3)!=0)); //INVALID VTABLE PTR ObjectType * type=tm.getObjectTypeFromAllocationHandle(allocationHandle); Index: vm/jitrino/src/codegenerator/ia32/Ia32IRManager.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32IRManager.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32IRManager.cpp (working copy) @@ -27,7 +27,6 @@ #include "Ia32Printer.h" #include "Ia32CodeGenerator.h" #include "Dominator.h" -#include "float.h" #include namespace Jitrino @@ -486,7 +485,7 @@ // it's just a self-check, as the currently assumed behaviour is that this method is invoked only once. assert(NULL == entryPointInst); - EntryPointPseudoInst * inst=new(memoryManager, methodDesc.getMethodSig()->getNumParams() * 2) EntryPointPseudoInst(this, instId++, cc); + EntryPointPseudoInst * inst=new(memoryManager, methodDesc.getNumParams() * 2) EntryPointPseudoInst(this, instId++, cc); fg->getEntryNode()->appendInst(inst); inst->assignOpcodeGroup(this); @@ -1503,7 +1502,7 @@ CGNode* node = (CGNode*)*it; if (node == exitNode) { if (!methodDesc.isStatic() - && (methodDesc.isSynchronized() || methodDesc.isMethodClassIsLikelyExceptionType())) + && (methodDesc.isSynchronized() || methodDesc.isParentClassIsLikelyExceptionType())) { BitSet * exitLs = node->getLiveAtEntry(); EntryPointPseudoInst * entryPointInst = getEntryPointInst(); @@ -1659,7 +1658,7 @@ #ifdef _EM64T_ MethodDesc& md = getMethodDesc(); if (!md.isStatic() - && (md.isSynchronized() || md.isMethodClassIsLikelyExceptionType())) { + && (md.isSynchronized() || md.isParentClassIsLikelyExceptionType())) { Type* thisType = entryPointInst->getOpnd(0)->getType(); entryPointInst->thisOpnd = newMemOpnd(thisType, MemOpndKind_StackAutoLayout, getRegOpnd(STACK_REG), 0); entryPointInst->getBasicBlock()->appendInst(newCopyPseudoInst(Mnemonic_MOV, entryPointInst->thisOpnd, entryPointInst->getOpnd(0))); @@ -1871,7 +1870,7 @@ #ifndef _EM64T_ bb->appendInst(newInst(Mnemonic_CMP, opnd, newImmOpnd(opnd->getType(), 0))); #else - bb->appendInst(newInst(Mnemonic_CMP, opnd,newImmOpnd(opnd->getType(), (Type::isCompressedReference(opnd->getType()->tag) || !opnd->getType()->isReference())? 0: (POINTER_SIZE_INT)compilationInterface.getHeapBase()))); + bb->appendInst(newInst(Mnemonic_CMP, opnd,newImmOpnd(opnd->getType(), (Type::isCompressedReference(opnd->getType()->tag) || !opnd->getType()->isReference())? 0: (POINTER_SIZE_INT)VMInterface::getHeapBase()))); #endif bb->appendInst(newBranchInst(Mnemonic_JZ, throwBasicBlock, oldTarget)); fg->addEdge(bb, throwBasicBlock, 0); @@ -1962,7 +1961,7 @@ value=(POINTER_SIZE_INT)((NamedType*)info->getValue(0))->getRuntimeIdentifier(); break; case Opnd::RuntimeInfo::Kind_MethodRuntimeId: - value=(POINTER_SIZE_INT)compilationInterface.getRuntimeMethodHandle((MethodDesc*)info->getValue(0)); + value=(POINTER_SIZE_INT)((MethodDesc*)info->getValue(0))->getMethodHandle(); break; case Opnd::RuntimeInfo::Kind_AllocationHandle: /* The value of the operand is [0]->ObjectType::getAllocationHandle() */ @@ -1993,7 +1992,7 @@ break; case Opnd::RuntimeInfo::Kind_VTableAddrOffset: /** The value of the operand is compilationInterface.getVTableOffset(), zero args */ - value=(POINTER_SIZE_INT)compilationInterface.getVTableOffset(); + value = (int64)VMInterface::getVTableOffset(); break; case Opnd::RuntimeInfo::Kind_VTableConstantAddr: /** The value of the operand is [0]->ObjectType::getVTable() */ @@ -2359,3 +2358,4 @@ } //namespace Ia32 } //namespace Jitrino + Index: vm/jitrino/src/codegenerator/ia32/Ia32RuntimeInterface.h =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32RuntimeInterface.h (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32RuntimeInterface.h (working copy) @@ -56,8 +56,7 @@ virtual void* getAddressOfSecurityObject(MethodDesc* methodDesc, const JitFrameContext* context) { assert(0); return NULL; } - virtual bool recompiledMethodEvent(BinaryRewritingInterface & binaryRewritingInterface, - MethodDesc * methodDesc, void * data); + virtual bool recompiledMethodEvent(MethodDesc * methodDesc, void * data); virtual bool getBcLocationForNative(MethodDesc* method, uint64 native_pc, uint16 *bc_pc); virtual bool getNativeLocationForBc(MethodDesc* method, uint16 bc_pc, uint64 *native_pc); Index: vm/jitrino/src/codegenerator/ia32/Ia32InternalProfiler.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32InternalProfiler.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32InternalProfiler.cpp (working copy) @@ -974,7 +974,7 @@ if(filter.isInitLocals.isInitialized) { if(!rt || ((rt->getKind() != Opnd::RuntimeInfo::Kind_MethodDirectAddr) && (rt->getKind() != Opnd::RuntimeInfo::Kind_MethodDirectAddr))) return false; - res = filter.isInitLocals.value == ((MethodDesc *)rt->getValue(0))->isInitLocals(); + res = filter.isInitLocals.value == false; if(filter.isInitLocals.isNegative) res = !res; Index: vm/jitrino/src/codegenerator/ia32/Ia32StackInfo.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32StackInfo.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32StackInfo.cpp (working copy) @@ -355,7 +355,7 @@ MethodDesc& md = irm.getMethodDesc(); if (!md.isStatic()) { #ifdef _EM64T_ - if ((md.isSynchronized() || md.isMethodClassIsLikelyExceptionType())) { + if ((md.isSynchronized() || md.isParentClassIsLikelyExceptionType())) { EntryPointPseudoInst * entryPointInst = irm.getEntryPointInst(); offsetOfThis = (uint32)entryPointInst->thisOpnd->getMemOpndSubOpnd(MemOpndSubOpndKind_Displacement)->getImmValue(); } else { Index: vm/jitrino/src/codegenerator/ia32/Ia32Printer.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32Printer.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32Printer.cpp (working copy) @@ -21,8 +21,6 @@ #include "Ia32Printer.h" #include "Log.h" -#include "../../vm/drl/DrlVMInterface.h" -#include "../../shared/PlatformDependant.h" #include "CGSupport.h" #include "PlatformDependant.h" @@ -1398,7 +1396,7 @@ void printRuntimeArgs(::std::ostream& os, uint32 opndCount, CallingConvention::OpndInfo * infos, JitFrameContext * context) { MemoryManager mm(0x1000, "printRuntimeOpndInternalHelper"); - DrlVMTypeManager tm(mm); tm.init(); + TypeManager tm(mm); tm.init(); os<getImmValue(); #else - return offsetOpnd->getImmValue() == (int64)irm.getCompilationInterface().getHeapBase()?0:(int32)offsetOpnd->getImmValue(); + return offsetOpnd->getImmValue() == (int64)VMInterface::getHeapBase() ? + 0 : (int32)offsetOpnd->getImmValue(); #endif } return MPTR_OFFSET_UNKNOWN; Index: vm/jitrino/src/codegenerator/ia32/Ia32GCMap.h =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32GCMap.h (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32GCMap.h (working copy) @@ -27,7 +27,6 @@ #include "Ia32IRManager.h" #include "Ia32StackInfo.h" #include "Ia32BCMap.h" -#include "DrlVMInterface.h" #ifdef _DEBUG #define GCMAP_TRACK_IDS @@ -55,7 +54,7 @@ const GCSafePointsInfo* getGCSafePointsInfo() const {return offsetsInfo;} static const POINTER_SIZE_INT* findGCSafePointStart(const POINTER_SIZE_INT* image, POINTER_SIZE_INT ip); - static void checkObject(DrlVMTypeManager& tm, const void* p); + static void checkObject(TypeManager& tm, const void* p); private: void processBasicBlock(IRManager& irm, const Node* block); Index: vm/jitrino/src/codegenerator/ia32/Ia32RuntimeInterface.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32RuntimeInterface.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32RuntimeInterface.cpp (working copy) @@ -42,7 +42,7 @@ void* RuntimeInterface::getAddressOfThis(MethodDesc * methodDesc, const JitFrameContext* context, bool isFirst) { assert(!methodDesc->isStatic()); - if (!methodDesc->isSynchronized() && !methodDesc->isMethodClassIsLikelyExceptionType()) { + if (!methodDesc->isSynchronized() && !methodDesc->isParentClassIsLikelyExceptionType()) { static const uint64 default_this=0; return (void*)&default_this; } Index: vm/jitrino/src/codegenerator/ia32/Ia32IRManager.h =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32IRManager.h (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32IRManager.h (working copy) @@ -32,7 +32,7 @@ #include "BitSet.h" #include "XTimer.h" #include "Log.h" -#include "../../shared/PlatformDependant.h" +#include "PlatformDependant.h" #include "CGSupport.h" #include "CompilationContext.h" #include "JITInstanceContext.h" Index: vm/jitrino/src/codegenerator/ia32/Ia32StackInfo.h =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32StackInfo.h (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32StackInfo.h (working copy) @@ -23,8 +23,6 @@ #define _IA32_STACK_INFO_H_ #include "CodeGenIntfc.h" -#include "open/types.h" -#include "jit_export.h" #include "MemoryManager.h" #include "VMInterface.h" #include "Type.h" Index: vm/jitrino/src/codegenerator/ia32/Ia32InternalTrace.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32InternalTrace.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32InternalTrace.cpp (working copy) @@ -21,9 +21,7 @@ #include "Ia32InternalTrace.h" #include "Log.h" -#include "jit_export.h" #include "Ia32Printer.h" -#include "../../vm/drl/DrlVMInterface.h" #include "Ia32GCMap.h" namespace Jitrino @@ -50,7 +48,7 @@ } static MemoryManager mm(0x100, "printRuntimeOpndInternalHelper"); -static DrlVMTypeManager *tm = NULL; +static TypeManager *tm = NULL; void __stdcall methodEntry(const char * methodName, uint32 argInfoCount, CallingConvention::OpndInfo * argInfos) { @@ -67,7 +65,7 @@ os<<")"<<::std::endl; if (tm == NULL) { - tm = new (mm) DrlVMTypeManager(mm); tm->init(); + tm = new (mm) TypeManager(mm); tm->init(); } for (uint32 i=0; iout(); os<<"__FIELD_WRITE__:"<=heapCeiling){ os<<"PROBABLY STATIC OR INVALID ADDRESS. DYNAMIC ADDRESSES MUST BE IN ["< _bbp("bbp"); -const uint32 gcFlagOffsetOffset = flagTLSSuspendRequestOffset(); +const uint32 gcFlagOffsetOffset = VMInterface::flagTLSSuspendRequestOffset(); Opnd* BBPolling::getOrCreateTLSBaseReg(Edge* e) @@ -837,3 +837,4 @@ }}; // namespace Ia32 + Index: vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.cpp (working copy) @@ -24,20 +24,12 @@ #include "Ia32CodeGenerator.h" #include "Ia32Printer.h" #include "EMInterface.h" -#include "DrlVMInterface.h" +#include "VMInterface.h" #include "Opcode.h" -#include "open/em_profile_access.h" -#include "open/vm.h" #include #include -#ifdef PLATFORM_POSIX -#define _isnan isnan -#define _finite finite -#endif - - namespace Jitrino { namespace Ia32{ @@ -1354,7 +1346,7 @@ CompareOp::Types zeroType = getCompareOpTypesFromCompareZeroOpTypes(opType); Opnd * op = (Opnd*) src; cmpToEflags(CompareOp::Eq, - zeroType, op, irManager.newImmOpnd(op->getType(),(zeroType == CompareOp::Ref) || (zeroType == CompareOp::CompRef) ? (POINTER_SIZE_INT)compilationInterface.getHeapBase() : 0)); + zeroType, op, irManager.newImmOpnd(op->getType(),(zeroType == CompareOp::Ref) || (zeroType == CompareOp::CompRef) ? (POINTER_SIZE_INT)VMInterface::getHeapBase() : 0)); #else cmpToEflags(CompareOp::Eq, getCompareOpTypesFromCompareZeroOpTypes(opType), (Opnd*)src, 0); @@ -1373,7 +1365,7 @@ CompareOp::Types zeroType = getCompareOpTypesFromCompareZeroOpTypes(opType); Opnd * op = (Opnd*) src; cmpToEflags(CompareOp::Eq, - zeroType, op, irManager.newImmOpnd(op->getType(),(zeroType == CompareOp::Ref) || (zeroType == CompareOp::CompRef) ? (POINTER_SIZE_INT)compilationInterface.getHeapBase() : 0)); + zeroType, op, irManager.newImmOpnd(op->getType(),(zeroType == CompareOp::Ref) || (zeroType == CompareOp::CompRef) ? (POINTER_SIZE_INT)VMInterface::getHeapBase() : 0)); #else cmpToEflags(CompareOp::Eq, getCompareOpTypesFromCompareZeroOpTypes(opType), (Opnd*)src, 0); @@ -1528,7 +1520,7 @@ if (compressed) { return irManager.newImmOpnd(typeManager.getCompressedNullObjectType(), 0); } else { - return irManager.newImmOpnd(typeManager.getNullObjectType(), (POINTER_SIZE_INT)compilationInterface.getHeapBase()); + return irManager.newImmOpnd(typeManager.getNullObjectType(), (POINTER_SIZE_INT)VMInterface::getHeapBase()); } #endif } @@ -1956,7 +1948,7 @@ appendInsts(irManager.newCopyPseudoInst(Mnemonic_MOV, tmp, opnd)); copyOpnd(dst, tmp); Type* unmanagedPtrType = typeManager.getUnmanagedPtrType(typeManager.getInt8Type()); - dst = simpleOp_I8(Mnemonic_ADD, dstType, dst, irManager.newImmOpnd(unmanagedPtrType, (POINTER_SIZE_INT)compilationInterface.getHeapBase())); + dst = simpleOp_I8(Mnemonic_ADD, dstType, dst, irManager.newImmOpnd(unmanagedPtrType, (POINTER_SIZE_INT)VMInterface::getHeapBase())); return dst; } else { Opnd * opnd = irManager.newMemOpndAutoKind(irManager.getTypeFromTag(memType), addr); @@ -1986,7 +1978,7 @@ Opnd* dst = irManager.newMemOpndAutoKind(irManager.getTypeFromTag(memType), addr); copyOpnd(dst, src); } else if(memType > Type::Float) { - src = simpleOp_I8(Mnemonic_SUB, src->getType(), src, irManager.newImmOpnd(typeManager.getIntPtrType(), (POINTER_SIZE_INT)compilationInterface.getHeapBase())); + src = simpleOp_I8(Mnemonic_SUB, src->getType(), src, irManager.newImmOpnd(typeManager.getIntPtrType(), (POINTER_SIZE_INT)VMInterface::getHeapBase())); Opnd * opnd = irManager.newMemOpndAutoKind(typeManager.compressType(src->getType()), addr); appendInsts(irManager.newCopyPseudoInst(Mnemonic_MOV, opnd, src)); } else { @@ -2298,7 +2290,7 @@ #ifdef _EM64T_ Opnd * base = irManager.newOpnd(irManager.getTypeFromTag(Type::Object)); - copyOpnd(base, irManager.newImmOpnd(base->getType(), (POINTER_SIZE_INT)compilationInterface.getHeapBase())); + copyOpnd(base, irManager.newImmOpnd(base->getType(), (POINTER_SIZE_INT)VMInterface::getHeapBase())); Opnd * tmp = irManager.newImmOpnd(irManager.getTypeFromTag(Type::UInt64), Opnd::RuntimeInfo::Kind_StringAddress, enclosingMethod, (void*)(POINTER_SIZE_INT)refToken); @@ -2460,7 +2452,7 @@ #else Opnd * vtableAddr=irManager.newOpnd(dstType); - int64 heapBase = (int64) compilationInterface.getVTableBase(); + int64 heapBase = (int64) VMInterface::getVTableBase(); Opnd * acc = simpleOp_I8(Mnemonic_ADD, dstType, (Opnd *)base, irManager.newImmOpnd(dstType, Opnd::RuntimeInfo::Kind_VTableAddrOffset)); Opnd * sourceVTableAddr=irManager.newMemOpnd(typeManager.getInt32Type(), acc, 0, 0, irManager.newImmOpnd(typeManager.getUInt32Type(), 0)); acc=irManager.newOpnd(dstType); @@ -2761,7 +2753,7 @@ irManager.newMemOpnd(typeManager.getUnmanagedPtrType(typeManager.getInt32Type()), MemOpndKind_Any, tlsBaseReg, - flagTLSThreadStateOffset()), + VMInterface::flagTLSThreadStateOffset()), (Opnd*)args[0])); #endif // PLATFORM_POSIX @@ -2785,12 +2777,12 @@ irManager.newMemOpnd(typeManager.getInt32Type(), MemOpndKind_Any, tlsBaseReg, - flagTLSThreadStateOffset()))); + VMInterface::flagTLSThreadStateOffset()))); appendInsts(irManager.newCopyPseudoInst(Mnemonic_MOV, irManager.newMemOpnd(typeManager.getInt32Type(), MemOpndKind_Any, tlsBaseReg, - flagTLSThreadStateOffset()), + VMInterface::flagTLSThreadStateOffset()), irManager.newImmOpnd(typeManager.getInt32Type(),1))); #endif @@ -2978,14 +2970,6 @@ #define FAST_PATH_MONITOR_EXIT_SUCCESS_PROB 0.99 //_______________________________________________________________________________________________________________ -// Check if we should inline synchronization - -bool InstCodeSelector::inlineSync(CompilationInterface::ObjectSynchronizationInfo& syncInfo) -{ - return false; -} - -//_______________________________________________________________________________________________________________ // Acquire monitor for an object void InstCodeSelector::tau_monitorEnter(CG_OpndHandle* obj, CG_OpndHandle* tauIsNonNull) Index: vm/jitrino/src/codegenerator/ia32/Ia32CodeEmitter.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32CodeEmitter.cpp (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32CodeEmitter.cpp (working copy) @@ -51,7 +51,7 @@ } - CompilationInterface::CodeBlockHeat getCodeSectionHeat(uint32 sectionID)const; + CodeBlockHeat getCodeSectionHeat(uint32 sectionID)const; protected: uint32 getNeedInfo()const{ return NeedInfo_LivenessInfo; } @@ -590,8 +590,7 @@ } //________________________________________________________________________________________ -bool RuntimeInterface::recompiledMethodEvent(BinaryRewritingInterface& binaryRewritingInterface, - MethodDesc * recompiledMethodDesc, +bool RuntimeInterface::recompiledMethodEvent(MethodDesc *recompiledMethodDesc, void * data) { Byte ** indirectAddr = (Byte **)recompiledMethodDesc->getIndirectAddress(); @@ -630,15 +629,15 @@ } //________________________________________________________________________________________ -CompilationInterface::CodeBlockHeat CodeEmitter::getCodeSectionHeat(uint32 sectionID)const +CodeBlockHeat CodeEmitter::getCodeSectionHeat(uint32 sectionID)const { - CompilationInterface::CodeBlockHeat heat; + CodeBlockHeat heat; if (irManager->getCompilationContext()->hasDynamicProfileToUse()) - heat = CompilationInterface::CodeBlockHeatDefault; + heat = CodeBlockHeatDefault; else if (sectionID==0) - heat = CompilationInterface::CodeBlockHeatMax; + heat = CodeBlockHeatMax; else - heat = CompilationInterface::CodeBlockHeatMin; + heat = CodeBlockHeatMin; return heat; } @@ -667,7 +666,7 @@ } uint32 handlerInfoCount=(uint32)exceptionHandlerInfos.size(); - irManager->getCompilationInterface().setNumExceptionHandler(handlerInfoCount); + irManager->getMethodDesc().setNumExceptionHandler(handlerInfoCount); for (uint32 i=0; igetCompilationInterface(). + irManager->getMethodDesc(). setExceptionHandlerInfo(i, (Byte*)info.regionStart, (Byte*)info.regionEnd, (Byte*)info.handlerAddr, @@ -931,3 +930,4 @@ + Index: vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.h =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.h (revision 523181) +++ vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.h (working copy) @@ -362,7 +362,7 @@ MemoryManager& getCodeSelectorMemoryManager(){ return codeSelector.methodCodeSelector.codeSelectorMemManager; } - Type * getMethodReturnType() { return getMethodDesc()->getMethodSig()->getReturnType(); } + Type * getMethodReturnType() { return getMethodDesc()->getReturnType(); } Opnd * sxtInt32(Opnd *opnd); Opnd * zxtInt32(Opnd *opnd); @@ -407,9 +407,6 @@ Type * getRuntimeIdType() {return typeManager.getUnmanagedPtrType(typeManager.getIntPtrType());} - // Check if we should inline synchronization - bool inlineSync(CompilationInterface::ObjectSynchronizationInfo& syncInfo); - // Check if we should generate tau instructions bool suppressTauInsts(){ return true; }; // Index: vm/jitrino/src/codegenerator/CodeGenIntfc.h =================================================================== --- vm/jitrino/src/codegenerator/CodeGenIntfc.h (revision 523181) +++ vm/jitrino/src/codegenerator/CodeGenIntfc.h (working copy) @@ -589,8 +589,7 @@ virtual void* getAddressOfSecurityObject(MethodDesc* methodDesc, const ::JitFrameContext* context) = 0; #endif - virtual bool recompiledMethodEvent(BinaryRewritingInterface & binaryRewritingInterface, - MethodDesc * methodDesc, void * data) = 0; + virtual bool recompiledMethodEvent(MethodDesc * methodDesc, void * data) = 0; virtual uint32 getInlineDepth(InlineInfoPtr ptr, uint32 offset) { return 0; } virtual Method_Handle getInlinedMethod(InlineInfoPtr ptr, uint32 offset, uint32 inline_depth) { return NULL; } Index: vm/jitrino/src/jet/compiler.cpp =================================================================== --- vm/jitrino/src/jet/compiler.cpp (revision 523181) +++ vm/jitrino/src/jet/compiler.cpp (working copy) @@ -1,4 +1,3 @@ - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -33,7 +32,7 @@ #include "jit_intf.h" -#include "../shared/mkernel.h" +#include "mkernel.h" //FIXME: needed for NOPs fix only, to be removed #include "enc_ia32.h" @@ -48,15 +47,15 @@ #if !defined(PROJECT_JET) #include "Jitrino.h" - #include "VMInterface.h" - #include "DrlVMInterface.h" #include "EMInterface.h" #include "JITInstanceContext.h" + /** + * A lock used to protect method's data in multi-threaded compilation. + * See VMInterface.h + * CompilationInterface::lockMethodData/unlockMethodData for details. + */ + extern Jitrino::Mutex g_compileLock; #else - /** - * See DrlVMInterface.h/g_compileLock and - * DrlCompilationInterface::lockMethodData/unlockMethodData for details. - */ static Jitrino::Mutex g_compileLock; #endif @@ -441,7 +440,7 @@ m_vmCode = (char*)method_allocate_code_block(m_method, m_hjit, total_code_size, 16/*fixme aligment*/, - CODE_BLOCK_HEAT_DEFAULT, + CodeBlockHeatDefault, 0, CAA_Allocate); m_infoBlock.set_code_start(m_vmCode); } @@ -1495,7 +1494,7 @@ ProfilingInterface* pi = jitContext->getProfilingInterface(); if (pi->isProfilingEnabled(ProfileType_EntryBackedge, JITProfilingRole_GEN)) { MemoryManager mm(128, "jet_profiling_mm"); - DrlVMMethodDesc md(m_method, m_hjit); + MethodDesc md(m_method, m_hjit); g_compileLock.lock(); @@ -1524,3 +1523,4 @@ }}; // ~namespace Jitrino::Jet + Index: vm/jitrino/src/jet/jet.cpp =================================================================== --- vm/jitrino/src/jet/jet.cpp (revision 523181) +++ vm/jitrino/src/jet/jet.cpp (working copy) @@ -139,7 +139,8 @@ #include #include "trace.h" -#include "../shared/mkernel.h" +#include "mkernel.h" +#include "PlatformDependant.h" #include #include Index: vm/jitrino/src/optimizer/simplifier.cpp =================================================================== --- vm/jitrino/src/optimizer/simplifier.cpp (revision 523181) +++ vm/jitrino/src/optimizer/simplifier.cpp (working copy) @@ -41,6 +41,7 @@ #include #include +#include "PlatformDependant.h" namespace Jitrino { /* @@ -50,21 +51,7 @@ * Implementation. Morgan Kaufmann, San Francisco, CA, 1997]. */ -#ifdef PLATFORM_POSIX -inline bool isFinite(double s) { - return (finite(s) != 0); -} -// isnan(double s) is declared in float.h -#else -inline bool isFinite(double s) { - return (_finite(s) != 0); -} -inline bool isnan(double s) { - return (_isnan(s) != 0); -} -#endif - DEFINE_SESSION_ACTION(SimplificationPass, simplify, "Perform simplification pass"); void SimplificationPass::_run(IRManager& irm) { @@ -3071,7 +3058,7 @@ case Type::Single: // single { float s = value.s; - if (!isFinite((double)s)) { + if (!finite((double)s)) { alwaysThrows = true; return genTauUnsafe()->getDst(); } @@ -3080,7 +3067,7 @@ case Type::Double: { double d = value.d; - if (!isFinite(d)) { + if (!finite(d)) { alwaysThrows = true; return genTauUnsafe()->getDst(); } Index: vm/jitrino/src/optimizer/Opnd.h =================================================================== --- vm/jitrino/src/optimizer/Opnd.h (revision 523181) +++ vm/jitrino/src/optimizer/Opnd.h (working copy) @@ -28,7 +28,6 @@ #include "open/types.h" #include "Type.h" -#include "Exceptions.h" #include "MemoryManager.h" namespace Jitrino { Index: vm/jitrino/src/optimizer/CodeGenerator.cpp =================================================================== --- vm/jitrino/src/optimizer/CodeGenerator.cpp (revision 523181) +++ vm/jitrino/src/optimizer/CodeGenerator.cpp (working copy) @@ -22,7 +22,6 @@ */ #include "CodeSelectors.h" -#include "../../vm/drl/DrlVMInterface.h" namespace Jitrino { @@ -132,7 +131,7 @@ MethodDesc* mdesc = (MethodDesc*)(*desc_it)->first; uint32 bcOffset = (uint32)(*desc_it)->second; //assert(dynamic_cast(mdesc)); // <-- some strange warning on Win32 here - *ptr++ = ptr_to_uint64(((DrlVMMethodDesc*)mdesc)->getDrlVMMethod()); + *ptr++ = ptr_to_uint64(mdesc->getMethodHandle()); *ptr++ = (POINTER_SIZE_INT)bcOffset; depth++; } Index: vm/jitrino/src/optimizer/multiplybyconstant.cpp =================================================================== --- vm/jitrino/src/optimizer/multiplybyconstant.cpp (revision 523181) +++ vm/jitrino/src/optimizer/multiplybyconstant.cpp (working copy) @@ -23,7 +23,6 @@ #undef STANDALONE_TEST -#include "assert.h" #include #include #include @@ -56,21 +55,12 @@ #include "Stl.h" #include "simplifier.h" -#include "open/types.h" #include "optarithmetic.h" namespace Jitrino { -#ifdef PLATFORM_POSIX -// isnan(double s) is declared in float.h -#else -inline bool isnan(double s) { - return (_isnan(s) != 0); -} -#endif - #ifndef DEBUG_MULTIPLYBYCONSTANT #define DEBUGPRINT(x) #define DEBUGPRINT2(x,y) Index: vm/jitrino/src/optimizer/escanalyzer.cpp =================================================================== --- vm/jitrino/src/optimizer/escanalyzer.cpp (revision 523181) +++ vm/jitrino/src/optimizer/escanalyzer.cpp (working copy) @@ -33,8 +33,7 @@ #include "ssa/SSA.h" #include "optpass.h" #include "devirtualizer.h" -#include "DrlVMInterface.h" -//#include "Windows.h" +#include "VMInterface.h" namespace Jitrino { @@ -1840,12 +1839,12 @@ mident->name=mname; mident->signature=msig; minfo->methodIdent=mident; - uint32 numpar = mdesc->getMethodSig()->getNumParams(); + uint32 numpar = mdesc->getNumParams(); minfo->numberOfArgs=numpar; ParamInfos* prminfos = new (globalMM) ParamInfos(globalMM); minfo->paramInfos=prminfos; minfo->retValueState=0; - if (mdesc->getMethodSig()->getReturnType()->isReference()) { + if (mdesc->getReturnType()->isReference()) { uint32 escstate = 3, bitstate = 0; for (it = cngNodes->begin( ); it != cngNodes->end( ); it++) { if ((*it)->nodeType==NT_EXITVAL) { @@ -1961,7 +1960,7 @@ << "." << methodDesc->getName() << methodDesc->getSignatureString() << " " << methodDesc << std::endl; Log::out() << " NumParams: " - << methodDesc->getMethodSig()->getNumParams()<< std::endl; + << methodDesc->getNumParams()<< std::endl; Log::out() << " isNative: " << methodDesc->isNative() << std::endl; Log::out() << " isStatic: " << methodDesc->isStatic() << std::endl; Log::out() << " isInstance: " << methodDesc->isInstance() << std::endl; @@ -1971,7 +1970,6 @@ Log::out() << " isInstanceInitializer: " << methodDesc->isInstanceInitializer() << std::endl; Log::out() << " isOverridden: " << methodDesc->isOverridden() << std::endl; - Log::out() << " isJavaByteCodes: " << methodDesc->isJavaByteCodes() << std::endl; } #endif @@ -1983,7 +1981,7 @@ returnOpnd = _opndManager.createSsaTmpOpnd(call->getDst()->getType()); IRManager* inlinedIRM = new (eaMemManager) IRManager(irManager.getMemoryManager(), irManager, *methodDesc, returnOpnd); - DrlVMCompilationInterface& ci= (DrlVMCompilationInterface&)inlinedIRM->getCompilationInterface(); + CompilationInterface& ci= inlinedIRM->getCompilationInterface(); bool cibcmap = ci.isBCMapInfoRequired(); if (cibcmap) { ci.setBCMapInfoRequired(false); @@ -2249,7 +2247,7 @@ Log::out() << "---------------" << std::endl; Log::out() << " NumParams: " - << mdesc->getMethodSig()->getNumParams()<< std::endl; + << mdesc->getNumParams()<< std::endl; Log::out() << " isNative: " << mdesc->isNative() << std::endl; Log::out() << " isStatic: " @@ -2266,8 +2264,6 @@ << mdesc->isInstanceInitializer() << std::endl; Log::out() << " isOverridden: " << mdesc->isOverridden() << std::endl; - Log::out() << " isJavaByteCodes: " - << mdesc->isJavaByteCodes() << std::endl; } if (_setState) { @@ -3054,7 +3050,6 @@ os << " isInitOnly " << fd->isInitOnly() << std::endl; os << " isVolatile " << fd->isVolatile() << std::endl; os << " isLiteral " << fd->isLiteral() << std::endl; - os << " isUnmanagedStatic " << fd->isUnmanagedStatic() << std::endl; os << " fldT " << tt->getName() <<" "<< tt->tag<< std::endl; os << " isObject " << tt->isObject() << std::endl; os << " isRef " << tt->isReference()<< std::endl; @@ -3116,16 +3111,13 @@ os << " isAbstract " << md->isAbstract() << std::endl; os << " isClassInitializer " << md->isClassInitializer() << std::endl; os << " isInstanceInitializer " << md->isInstanceInitializer() << std::endl; - os << " isInitLocals " << md->isInitLocals() << std::endl; os << " isOverridden " << md->isOverridden() << std::endl; - os << " isJavaByteCodes " << md->isJavaByteCodes() << std::endl; os << " Name " << md->getName() << std::endl; os << " Signature " << md->getSignatureString() << std::endl; - MethodSignatureDesc* msd = md->getMethodSig(); - uint32 n=msd->getNumParams(); + uint32 n=md->getNumParams(); os << " Params " << n << std::endl; for (uint32 i = 0; i < n; i++) { - Type* tt = msd->getParamType(i); + Type* tt = md->getParamType(i); os << " << "<> " << tt->getName() <<" "<< tt->tag<< std::endl; os << " isObject " << tt->isObject(); os << " isRef " << tt->isReference()<< std::endl; @@ -3300,7 +3292,7 @@ EscAnalyzer::CnGNode* EscAnalyzer::addCnGNode_mp(Inst* inst, MethodDesc* md, uint32 ntype, uint32 narg) { - Type* type = md->getMethodSig()->getParamType(narg); + Type* type = md->getParamType(narg); CnGNode* cgnode = addCnGNode(inst, type, ntype); // new CG node cgnode->opndId = 0; @@ -3384,7 +3376,6 @@ CnGNode* cgnode; uint32 ntype=0; MethodDesc* md; - MethodSignatureDesc* msd; uint32 n; bool addinst; Inst* method_inst; @@ -3590,11 +3581,10 @@ } } md=inst->asMethodInst()->getMethodDesc(); - msd = md->getMethodSig(); - n=msd->getNumParams(); + n=md->getNumParams(); addinst=false; for (uint32 i = 0; i < n; i++) { - Type* tt = msd->getParamType(i); + Type* tt = md->getParamType(i); if (!tt->isReference()) { continue; } @@ -3649,11 +3639,10 @@ } else { md=method_inst->asMethodInst()->getMethodDesc(); } - msd = md->getMethodSig(); - n=msd->getNumParams(); + n=md->getNumParams(); addinst=false; for (uint32 i = 0; i < n; i++) { - Type* tt = msd->getParamType(i); + Type* tt = md->getParamType(i); if (!tt->isReference()) { continue; } @@ -3868,7 +3857,6 @@ CnGNode* cgn_src; uint32 ntype=0; MethodDesc* md; - MethodSignatureDesc* msd; uint32 n; Inst* method_inst; bool not_exam = false; @@ -3984,10 +3972,9 @@ case Op_DirectCall: // call md=inst->asMethodInst()->getMethodDesc(); - msd = md->getMethodSig(); - n=msd->getNumParams(); + n=md->getNumParams(); for (uint32 i = 0; i < n; i++) { - Type* tt = msd->getParamType(i); + Type* tt = md->getParamType(i); if (!tt->isReference()) continue; cgnode=findCnGNode_mp(inst->getId(),i); @@ -4006,10 +3993,9 @@ } else { md=method_inst->asMethodInst()->getMethodDesc(); } - msd = md->getMethodSig(); - n=msd->getNumParams(); + n=md->getNumParams(); for (uint32 i = 0; i < n; i++) { - Type* tt = msd->getParamType(i); + Type* tt = md->getParamType(i); if (!tt->isReference()) continue; cgnode = findCnGNode_mp(inst->getId(),i); @@ -4203,7 +4189,7 @@ os << ((MethodDesc*)(*it)->refObj)->getParentType()->getName() << "::"; os << ((MethodDesc*)(*it)->refObj)->getName() << std::endl; os << " "; - os << ((MethodDesc*)(*it)->refObj)->getMethodSig()->getParamType((*it)->opndId)->getName(); + os << ((MethodDesc*)(*it)->refObj)->getParamType((*it)->opndId)->getName(); } if ((*it)->nodeType & NT_STFLD) { //field node fd = ((Inst*)(*it)->refObj)->asFieldAccessInst()->getFieldDesc(); @@ -6675,3 +6661,4 @@ } //namespace Jitrino + Index: vm/jitrino/src/optimizer/lazyexceptionopt.cpp =================================================================== --- vm/jitrino/src/optimizer/lazyexceptionopt.cpp (revision 523181) +++ vm/jitrino/src/optimizer/lazyexceptionopt.cpp (working copy) @@ -66,7 +66,7 @@ BitSet excOpnds(leMemManager,irManager.getOpndManager().getNumSsaOpnds()); StlDeque candidateSet(leMemManager); optCandidates = new (leMemManager) OptCandidates(leMemManager); - CompilationInterface::MethodSideEffect m_sideEff = compInterface.getMethodHasSideEffect(&md); + Method_Side_Effects m_sideEff = md.getSideEffect(); const Nodes& nodes = irManager.getFlowGraph().getNodes(); Nodes::const_iterator niter; @@ -90,10 +90,10 @@ isExceptionInit = md.isInstanceInitializer() && md.getParentType()->isLikelyExceptionType(); // core api exception init - if (m_sideEff == CompilationInterface::MSE_UNKNOWN && isExceptionInit + if (m_sideEff == MSE_Unknown && isExceptionInit && strncmp(md.getParentType()->getName(),"java/lang/",10) == 0) { - m_sideEff = CompilationInterface::MSE_NO; - compInterface.setMethodHasSideEffect(&md,m_sideEff); + m_sideEff = MSE_False; + md.setSideEffect(m_sideEff); #ifdef _DEBUG if (Log::isEnabled()) { Log::out() << " core api exc "; md.printFullName(Log::out()); @@ -137,9 +137,9 @@ #endif } } - if (m_sideEff==CompilationInterface::MSE_UNKNOWN) + if (m_sideEff == MSE_Unknown) if (instHasSideEffect(inst)) { - m_sideEff=CompilationInterface::MSE_YES; + m_sideEff = MSE_True; #ifdef _DEBUG if (Log::isEnabled()) { Log::out() << "~~~~~~inst sideEff "; @@ -149,8 +149,8 @@ } } } - if (compInterface.getMethodHasSideEffect(&md)==CompilationInterface::MSE_UNKNOWN) { - if (m_sideEff == CompilationInterface::MSE_UNKNOWN) + if (md.getSideEffect() == MSE_Unknown) { + if (m_sideEff == MSE_Unknown) if (isExceptionInit && isArgCheckNull) { #ifdef _DEBUG if (Log::isEnabled()) { @@ -158,10 +158,10 @@ md.printFullName(Log::out()); Log::out() << std::endl; } #endif - m_sideEff = CompilationInterface::MSE_NULL_PARAM; + m_sideEff = MSE_True_Null_Param; } else - m_sideEff = CompilationInterface::MSE_NO; - compInterface.setMethodHasSideEffect(&md,m_sideEff); + m_sideEff = MSE_False; + md.setSideEffect(m_sideEff); } for(niter = nodes.begin(); niter != nodes.end(); ++niter) { @@ -633,7 +633,7 @@ LazyExceptionOpt::methodCallHasSideEffect(Inst* inst) { uint32 opcode = inst->getOpcode(); MethodDesc* cmd; - CompilationInterface::MethodSideEffect mse; + Method_Side_Effects mse; if (opcode==Op_DirectCall || opcode==Op_TauVirtualCall) { cmd = inst->asMethodCallInst()->getMethodDesc(); @@ -657,25 +657,25 @@ } #endif - mse=compInterface.getMethodHasSideEffect(cmd); + mse = cmd->getSideEffect(); #ifdef _DEBUG - if (mse!=CompilationInterface::MSE_UNKNOWN) { + if (mse != MSE_Unknown) { if (Log::isEnabled()) { Log::out() << " checkMC: prev.set sideEff " << mse << " "; inst->print(Log::out()); Log::out() << std::endl; } } #endif - if (mse==CompilationInterface::MSE_YES) { + if (mse == MSE_True) { return true; } - if (mse==CompilationInterface::MSE_NO) { + if (mse == MSE_False) { return false; } // core api exception init if (cmd->isInstanceInitializer() && cmd->getParentType()->isLikelyExceptionType() && strncmp(cmd->getParentType()->getName(),"java/lang/",10) == 0) { - compInterface.setMethodHasSideEffect(cmd,CompilationInterface::MSE_NO); + cmd->setSideEffect(MSE_False); #ifdef _DEBUG if (Log::isEnabled()) { Log::out() << " checkMC: core api exc "; @@ -719,7 +719,7 @@ return true; // cannot compile before (to fix vm) } - if (mse==CompilationInterface::MSE_UNKNOWN) { // try to compile method + if (mse == MSE_Unknown) { // try to compile method if (!compInterface.compileMethod(cmd)) { #ifdef _DEBUG if (Log::isEnabled()) { @@ -728,22 +728,22 @@ #endif return true; } else { - mse = compInterface.getMethodHasSideEffect(cmd); + mse = cmd->getSideEffect(); #ifdef _DEBUG if (Log::isEnabled()) { Log::out() << " checkMC: method was compiled, sideEff " << mse << std::endl; } #endif - if (mse==CompilationInterface::MSE_YES) + if (mse == MSE_True) return true; - if (mse==CompilationInterface::MSE_NO) { + if (mse == MSE_False) { return false; } } } - if (mse==CompilationInterface::MSE_NULL_PARAM) { + if (mse == MSE_True_Null_Param) { uint32 nsrc=inst->getNumSrcOperands(); bool mayBeNull; if (nsrc>3) { @@ -1112,3 +1112,4 @@ } //namespace Jitrino + Index: vm/jitrino/src/optimizer/syncopt.cpp =================================================================== --- vm/jitrino/src/optimizer/syncopt.cpp (revision 523181) +++ vm/jitrino/src/optimizer/syncopt.cpp (working copy) @@ -569,6 +569,30 @@ } } +// synchronization inlining +struct ObjectSynchronizationInfo { + uint32 threadIdReg; // the register number that holds id of the current thread + uint32 syncHeaderOffset; // offset in bytes of the sync header from the start of the object + uint32 syncHeaderWidth; // width in bytes of the sync header + uint32 lockOwnerOffset; // offset in bytes of the lock owner field from the start of the object + uint32 lockOwnerWidth; // width in bytes of the lock owner field in the sync header + bool jitClearsCcv; // whether the JIT needs to clear ar.ccv +}; + +// should flush to zero be allowed for floating-point operations ? +//bool isFlushToZeroAllowed() { +// return flushToZeroAllowed; +//} +// +// Returns true if jit may inline VM functionality for monitorenter and monitorexit +// If true is returned 'syncInfo' is filled in with the synchronization parameters. +// +bool mayInlineObjectSynchronization(ObjectSynchronizationInfo & syncInfo) { + assert(0); + return false; +} + + void SyncOpt::runPass() { if (Log::isEnabled()) { @@ -630,13 +654,12 @@ uint32 lockWidth = 2; - CompilationInterface &compIntfc = irManager.getCompilationInterface(); - CompilationInterface::ObjectSynchronizationInfo syncInfo; - if (compIntfc.mayInlineObjectSynchronization(syncInfo)) + ObjectSynchronizationInfo syncInfo; + if (mayInlineObjectSynchronization(syncInfo)) lockWidth = syncInfo.lockOwnerWidth; - CompilationInterface::ObjectSynchronizationInfo syncInfoFromVM; - bool mayInlineSync = irManager.getCompilationInterface().mayInlineObjectSynchronization(syncInfoFromVM); + ObjectSynchronizationInfo syncInfoFromVM; + bool mayInlineSync = mayInlineObjectSynchronization(syncInfoFromVM); if (flags.balance && mayInlineSync) { TypeManager &typeManager = irManager.getTypeManager(); Index: vm/jitrino/src/optimizer/IRBuilder.cpp =================================================================== --- vm/jitrino/src/optimizer/IRBuilder.cpp (revision 523181) +++ vm/jitrino/src/optimizer/IRBuilder.cpp (working copy) @@ -310,9 +310,9 @@ simplifier = new (mm) IRBuilderSimplifier(*this); CompilationInterface* ci = getCompilationContext()->getVMCompilationInterface(); - irBuilderFlags.insertWriteBarriers = ci->insertWriteBarriers(); + irBuilderFlags.insertWriteBarriers = ci->needWriteBarriers(); irBuilderFlags.isBCMapinfoRequired = ci->isBCMapInfoRequired(); - irBuilderFlags.compressedReferences = irBuilderFlags.compressedReferences || ci->areReferencesCompressed(); + irBuilderFlags.compressedReferences = irBuilderFlags.compressedReferences || VMInterface::areReferencesCompressed(); if (irBuilderFlags.isBCMapinfoRequired) { MethodDesc* meth = irm->getCompilationInterface().getMethodToCompile(); @@ -2025,10 +2025,7 @@ Opnd* dst = lookupHash(Op_LdStaticAddr, fieldDesc->getId()); if (dst) return dst; - if (fieldDesc->isUnmanagedStatic()) { - // can't mark an unmanaged pointer as non-null - dst = createOpnd(typeManager->getIntPtrType()); - } else if (irBuilderFlags.compressedReferences && type->isObject()) { + if (irBuilderFlags.compressedReferences && type->isObject()) { // until VM type system is upgraded, // fieldDesc type will have uncompressed ref type; // compress it Index: vm/jitrino/src/optimizer/constantfolder.cpp =================================================================== --- vm/jitrino/src/optimizer/constantfolder.cpp (revision 523181) +++ vm/jitrino/src/optimizer/constantfolder.cpp (working copy) @@ -28,6 +28,7 @@ #include #include +#include "PlatformDependant.h" /* * The constant folding optimization is described in [S.Muchnick. Advanced Compiler @@ -39,10 +40,6 @@ using namespace std; -inline int isFinite(double s) { - return finite(s); -} - inline float _chgsign(float f) { return copysignf(f, signbit(f) ? (float)1.0 : (float)-1.0 ); } @@ -50,18 +47,6 @@ inline double _chgsign(double d) { return copysign(d, signbit(d) ? 1.0 : -1.0 ); } - -// isnan(double s) is declared in float.h -#else -inline int isFinite(double s) { - return _finite(s); -} - -// _chgsign(double d) is declared in float.h - -inline int isnan(double s) { - return _isnan(s); -} #endif // use templates here to decrease code to write for float2int below. @@ -94,7 +79,7 @@ inline tointtype float2int(fromfloattype f) { if (isnan(f)) return (tointtype) 0; - if (isFinite(f) && + if (finite(f) && (((fromfloattype(minint(0))) < f) && (f < fromfloattype(maxint(0))))) return (tointtype) f; // both C++ and Java truncate @@ -106,7 +91,7 @@ inline tointtype float2uint(fromfloattype s) { if (isnan(s) || (s < 0.0)) return (tointtype) 0; - if (isFinite(s) && (s < maxuintasfloat(0))) + if (finite(s) && (s < maxuintasfloat(0))) return (tointtype) s; return maxuint(0); } Index: vm/jitrino/src/optimizer/devirtualizer.cpp =================================================================== --- vm/jitrino/src/optimizer/devirtualizer.cpp (revision 523181) +++ vm/jitrino/src/optimizer/devirtualizer.cpp (working copy) @@ -26,7 +26,6 @@ #include "Dominator.h" #include "inliner.h" #include "EMInterface.h" -#include "open/vm.h" namespace Jitrino { @@ -460,11 +459,13 @@ // Do not devirtualize - there were no real calls here return; } - Log::out() << "Valued type: " << class_get_name(vtable_get_class((VTable_Handle)vtHandle)) << std::endl; // get desired MethodDesc object assert(vtHandle != 0); - ObjectType* clssObjectType = _typeManager.getObjectType(vtable_get_class((VTable_Handle)vtHandle)); + ObjectType* clssObjectType = _typeManager.getObjectType(VMInterface::getTypeHandleFromVTable((void*)vtHandle)); + Log::out() << "Valued type: "; + clssObjectType->print(Log::out()); + Log::out() << std::endl; candidateMeth = regionIRM.getCompilationInterface().resolveMethod(clssObjectType, origMethodDesc->getName(), origMethodDesc->getSignatureString()); Log::out() << "candidateMeth: "<< std::endl; candidateMeth->printFullName(Log::out()); @@ -482,7 +483,7 @@ } else if (profileSelection) { ClassHierarchyMethodIterator* iterator = regionIRM.getCompilationInterface().getClassHierarchyMethodIterator(baseType, origMethodDesc); - if(iterator) { + if(iterator->isValid()) { ProfilingInterface* pi = cc->getProfilingInterface(); while (iterator->hasNext()) { MethodDesc* tmpMeth = iterator->getNext(); @@ -502,7 +503,7 @@ } } if (candidateMeth) { - jitrino_assert(regionIRM.getCompilationInterface(), origMethodDesc->getParentType()->isClass()); + jitrino_assert(origMethodDesc->getParentType()->isClass()); methodInst->setMethodDesc(candidateMeth); // // Try to guard this call Index: vm/jitrino/src/optimizer/inliner.cpp =================================================================== --- vm/jitrino/src/optimizer/inliner.cpp (revision 523181) +++ vm/jitrino/src/optimizer/inliner.cpp (working copy) @@ -21,6 +21,7 @@ * */ +#include "EMInterface.h" #include "Log.h" #include "methodtable.h" #include "inliner.h" @@ -31,7 +32,6 @@ #include "Loop.h" #include "simplifier.h" #include "JavaByteCodeParser.h" -#include "EdgeProfiler.h" #include "StaticProfiler.h" #include "optimizer.h" @@ -444,15 +444,12 @@ bool Inliner::isLeafMethod(MethodDesc& methodDesc) { - if(methodDesc.isJavaByteCodes()) { - uint32 size = methodDesc.getByteCodeSize(); - const Byte* bytecodes = methodDesc.getByteCodes(); - ByteCodeParser parser((const uint8*)bytecodes,size); - JavaByteCodeLeafSearchCallback leafTester; - parser.parse(&leafTester); - return leafTester.isLeaf(); - } - return false; + uint32 size = methodDesc.getByteCodeSize(); + const Byte* bytecodes = methodDesc.getByteCodes(); + ByteCodeParser parser((const uint8*)bytecodes,size); + JavaByteCodeLeafSearchCallback leafTester; + parser.parse(&leafTester); + return leafTester.isLeaf(); } void Index: vm/jitrino/src/optimizer/optimizer.cpp =================================================================== --- vm/jitrino/src/optimizer/optimizer.cpp (revision 523181) +++ vm/jitrino/src/optimizer/optimizer.cpp (working copy) @@ -59,7 +59,6 @@ #include "StaticProfiler.h" #include "lazyexceptionopt.h" #include "CompilationContext.h" -#include "EdgeProfiler.h" #include "PMFAction.h" namespace Jitrino { Index: vm/jitrino/src/vm/drl/DrlEMInterface.cpp =================================================================== --- vm/jitrino/src/vm/drl/DrlEMInterface.cpp (revision 523181) +++ vm/jitrino/src/vm/drl/DrlEMInterface.cpp (working copy) @@ -14,23 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* COPYRIGHT_NOTICE */ -/** -* @author Mikhail Y. Fursov -* @version $Revision$ -*/ - -#include "open/em_profile_access.h" -#include "DrlEMInterface.h" -#include "DrlVMInterface.h" +#include "EMInterface.h" #include "JITInstanceContext.h" #include namespace Jitrino { -PC_Handle DrlProfilingInterface::getPCHandle(ProfileType type) const { +PC_Handle ProfilingInterface::getPCHandle(ProfileType type) const { switch (type) { case ProfileType_EntryBackedge: return ebPCHandle; @@ -44,31 +36,31 @@ return NULL; } -MethodProfile* DrlProfilingInterface::getMethodProfile(MemoryManager& mm, ProfileType type, MethodDesc& md, JITProfilingRole role) const { +MethodProfile* ProfilingInterface::getMethodProfile(MemoryManager& mm, ProfileType type, MethodDesc& md, JITProfilingRole role) const { - Method_Profile_Handle mpHandle = profileAccessInterface->get_method_profile(emHandle, getPCHandle(type), ((DrlVMMethodDesc&)md).getDrlVMMethod()); + Method_Profile_Handle mpHandle = profileAccessInterface->get_method_profile(emHandle, getPCHandle(type), md.getMethodHandle()); if (mpHandle==0) { return NULL; } MethodProfile* p = NULL; if (type == ProfileType_Edge) { - p = new (mm) DrlEdgeMethodProfile(mpHandle, md, profileAccessInterface); + p = new (mm) EdgeMethodProfile(mpHandle, md, profileAccessInterface); } else if (type == ProfileType_Value) { - p = new (mm) DrlValueMethodProfile(mpHandle, md, profileAccessInterface); + p = new (mm) ValueMethodProfile(mpHandle, md, profileAccessInterface); } else { uint32* eCounter = (uint32*)profileAccessInterface->eb_profiler_get_entry_counter_addr(mpHandle); uint32* bCounter = (uint32*)profileAccessInterface->eb_profiler_get_backedge_counter_addr(mpHandle); - p = new (mm) DrlEntryBackedgeMethodProfile(mpHandle, md, eCounter, bCounter); + p = new (mm) EntryBackedgeMethodProfile(mpHandle, md, eCounter, bCounter); } return p; } -Method_Profile_Handle DrlProfilingInterface::getMethodProfileHandle(ProfileType type, MethodDesc& md) const { - return profileAccessInterface->get_method_profile(emHandle, getPCHandle(type), ((DrlVMMethodDesc&)md).getDrlVMMethod()); +Method_Profile_Handle ProfilingInterface::getMethodProfileHandle(ProfileType type, MethodDesc& md) const { + return profileAccessInterface->get_method_profile(emHandle, getPCHandle(type), md.getMethodHandle()); } -bool DrlProfilingInterface::hasMethodProfile(ProfileType type, MethodDesc& md, JITProfilingRole role) const { +bool ProfilingInterface::hasMethodProfile(ProfileType type, MethodDesc& md, JITProfilingRole role) const { PC_Handle pcHandle = getPCHandle(type); @@ -79,13 +71,13 @@ return false; } if (profileAccessInterface != NULL) { - Method_Profile_Handle mpHandle = profileAccessInterface->get_method_profile(emHandle, pcHandle, ((DrlVMMethodDesc&)md).getDrlVMMethod()); + Method_Profile_Handle mpHandle = profileAccessInterface->get_method_profile(emHandle, pcHandle, md.getMethodHandle()); return mpHandle!=0; } return false; } -uint32 DrlProfilingInterface::getProfileMethodCount(MethodDesc& md, JITProfilingRole role) const { +uint32 ProfilingInterface::getProfileMethodCount(MethodDesc& md, JITProfilingRole role) const { assert(jitRole == role); PC_Handle pcHandle = getPCHandle(ProfileType_Edge); ProfileType pcType = ProfileType_Edge; @@ -94,7 +86,7 @@ pcType = ProfileType_EntryBackedge; } assert (pcHandle != NULL); - Method_Handle methodHandle = ((DrlVMMethodDesc&)md).getDrlVMMethod(); + Method_Handle methodHandle = md.getMethodHandle(); Method_Profile_Handle mph = profileAccessInterface->get_method_profile(emHandle, pcHandle, methodHandle); if (mph == NULL) { return 0; @@ -108,7 +100,7 @@ return *counterAddr; } -bool DrlProfilingInterface::enableProfiling(PC_Handle pc, JITProfilingRole role) { +bool ProfilingInterface::enableProfiling(PC_Handle pc, JITProfilingRole role) { EM_PCTYPE _pcType = profileAccessInterface->get_pc_type(emHandle, pc); if (_pcType != EM_PCTYPE_EDGE && _pcType != EM_PCTYPE_ENTRY_BACKEDGE && _pcType != EM_PCTYPE_VALUE) { return false; @@ -144,27 +136,27 @@ return profilingEnabled; } -bool DrlProfilingInterface::isProfilingEnabled(ProfileType pcType, JITProfilingRole role) const { +bool ProfilingInterface::isProfilingEnabled(ProfileType pcType, JITProfilingRole role) const { if(!profilingEnabled || (jitRole != role) || (getPCHandle(pcType) == NULL)){ return false; } return true; } -EntryBackedgeMethodProfile* DrlProfilingInterface::createEBMethodProfile(MemoryManager& mm, MethodDesc& md) { +EntryBackedgeMethodProfile* ProfilingInterface::createEBMethodProfile(MemoryManager& mm, MethodDesc& md) { assert(isProfilingEnabled(ProfileType_EntryBackedge, JITProfilingRole_GEN)); PC_Handle pcHandle = getPCHandle(ProfileType_EntryBackedge); - Method_Profile_Handle mpHandle = profileAccessInterface->eb_profiler_create_profile(pcHandle, ((DrlVMMethodDesc&)md).getDrlVMMethod()); + Method_Profile_Handle mpHandle = profileAccessInterface->eb_profiler_create_profile(pcHandle, md.getMethodHandle()); assert(mpHandle!=0); uint32* eCounter = (uint32*)profileAccessInterface->eb_profiler_get_entry_counter_addr(mpHandle); uint32* bCounter = (uint32*)profileAccessInterface->eb_profiler_get_backedge_counter_addr(mpHandle); - DrlEntryBackedgeMethodProfile* p = new (mm) DrlEntryBackedgeMethodProfile(mpHandle, md, eCounter, bCounter); + EntryBackedgeMethodProfile* p = new (mm) EntryBackedgeMethodProfile(mpHandle, md, eCounter, bCounter); return p; } -EdgeMethodProfile* DrlProfilingInterface::createEdgeMethodProfile( MemoryManager& mm, +EdgeMethodProfile* ProfilingInterface::createEdgeMethodProfile( MemoryManager& mm, MethodDesc& md, uint32 numCounters, uint32* counterKeys, @@ -173,14 +165,14 @@ assert(isProfilingEnabled(ProfileType_Edge, JITProfilingRole_GEN)); PC_Handle pcHandle = getPCHandle(ProfileType_Edge); Method_Profile_Handle mpHandle = profileAccessInterface->edge_profiler_create_profile( - pcHandle, ((DrlVMMethodDesc&)md).getDrlVMMethod(), numCounters, counterKeys, checkSum); + pcHandle, md.getMethodHandle(), numCounters, counterKeys, checkSum); assert( mpHandle != NULL ); - DrlEdgeMethodProfile* p = new (mm) DrlEdgeMethodProfile(mpHandle, md, profileAccessInterface); + EdgeMethodProfile* p = new (mm) EdgeMethodProfile(mpHandle, md, profileAccessInterface); return p; } -ValueMethodProfile* DrlProfilingInterface::createValueMethodProfile(MemoryManager& mm, +ValueMethodProfile* ProfilingInterface::createValueMethodProfile(MemoryManager& mm, MethodDesc& md, uint32 numKeys, uint32* Keys) @@ -188,15 +180,15 @@ assert(isProfilingEnabled(ProfileType_Value, JITProfilingRole_GEN)); PC_Handle pcHandle = getPCHandle(ProfileType_Value); Method_Profile_Handle mpHandle = profileAccessInterface->value_profiler_create_profile( - pcHandle, ((DrlVMMethodDesc&)md).getDrlVMMethod(), numKeys, Keys); + pcHandle, md.getMethodHandle(), numKeys, Keys); assert(mpHandle != NULL); - DrlValueMethodProfile* p = new (mm) DrlValueMethodProfile(mpHandle, md, profileAccessInterface); + ValueMethodProfile* p = new (mm) ValueMethodProfile(mpHandle, md, profileAccessInterface); return p; } -uint32 DrlProfilingInterface::getMethodEntryThreshold() const { +uint32 ProfilingInterface::getMethodEntryThreshold() const { PC_Handle pcHandle = getPCHandle(ProfileType_Edge); if (pcHandle != NULL) { return profileAccessInterface->edge_profiler_get_entry_threshold(pcHandle); @@ -207,7 +199,7 @@ return 0; } -uint32 DrlProfilingInterface::getBackedgeThreshold() const { +uint32 ProfilingInterface::getBackedgeThreshold() const { PC_Handle pcHandle = getPCHandle(ProfileType_Edge); if (pcHandle != NULL) { return profileAccessInterface->edge_profiler_get_backedge_threshold(pcHandle); @@ -218,58 +210,42 @@ return 0; } -bool DrlProfilingInterface::isEBProfilerInSyncMode() const { +bool ProfilingInterface::isEBProfilerInSyncMode() const { PC_Handle pcHandle = getPCHandle(ProfileType_EntryBackedge); assert(pcHandle!=NULL); return profileAccessInterface->eb_profiler_is_in_sync_mode(pcHandle)!=0; } -PC_Callback_Fn* DrlProfilingInterface::getEBProfilerSyncModeCallback() const { +ProfilingInterface::PC_Callback_Fn* ProfilingInterface::getEBProfilerSyncModeCallback() const { assert(profileAccessInterface->eb_profiler_sync_mode_callback!=NULL); return (PC_Callback_Fn*)profileAccessInterface->eb_profiler_sync_mode_callback; } - -DrlEdgeMethodProfile::DrlEdgeMethodProfile (Method_Profile_Handle handle, MethodDesc& md, - EM_ProfileAccessInterface* _profileAccessInterface) -: EdgeMethodProfile(handle, md), profileAccessInterface(_profileAccessInterface) -{ -} - - -uint32 DrlEdgeMethodProfile::getNumCounters() const { +uint32 EdgeMethodProfile::getNumCounters() const { return profileAccessInterface->edge_profiler_get_num_counters(getHandle()); } -uint32 DrlEdgeMethodProfile::getCheckSum() const { +uint32 EdgeMethodProfile::getCheckSum() const { return profileAccessInterface->edge_profiler_get_checksum(getHandle()); } -uint32* DrlEdgeMethodProfile::getEntryCounter() const { +uint32* EdgeMethodProfile::getEntryCounter() const { return (uint32*)profileAccessInterface->edge_profiler_get_entry_counter_addr(getHandle()); } -uint32* DrlEdgeMethodProfile::getCounter(uint32 key) const { +uint32* EdgeMethodProfile::getCounter(uint32 key) const { uint32* counter = (uint32*)profileAccessInterface->edge_profiler_get_counter_addr(getHandle(), key); return counter; } -// Value profile -DrlValueMethodProfile::DrlValueMethodProfile(Method_Profile_Handle handle, MethodDesc& md, EM_ProfileAccessInterface* _profileAccessInterface) -: ValueMethodProfile(handle, md), profileAccessInterface(_profileAccessInterface) { -} - -POINTER_SIZE_INT DrlValueMethodProfile::getTopValue(uint32 instructionKey) const { +POINTER_SIZE_INT ValueMethodProfile::getTopValue(uint32 instructionKey) const { return profileAccessInterface->value_profiler_get_top_value(getHandle(), instructionKey); } -void DrlValueMethodProfile::dumpValues(std::ostream& os) const { +void ValueMethodProfile::dumpValues(std::ostream& os) const { profileAccessInterface->value_profiler_dump_values(getHandle(), os); } - } //namespace - - Index: vm/jitrino/src/vm/drl/DrlVMInterface.cpp =================================================================== --- vm/jitrino/src/vm/drl/DrlVMInterface.cpp (revision 523181) +++ vm/jitrino/src/vm/drl/DrlVMInterface.cpp (working copy) @@ -25,37 +25,26 @@ #include #include -#include "DrlVMInterface.h" +#include "open/hythread_ext.h" + +#include "Type.h" +#include "VMInterface.h" #include "CompilationContext.h" #include "Log.h" #include "JITInstanceContext.h" -#include "jit_intf.h" -#include "open/hythread_ext.h" +#include "PlatformDependant.h" +#include "mkernel.h" +/** +* @brief A lock used to protect method's data in multi-threaded compilation. +*/ +Jitrino::Mutex g_compileLock; namespace Jitrino { -Mutex g_compileLock; -////////////////////////////////////////////////////////////////////////////// -// Utilities -////////////////////////////////////////////////////////////////////////////// -Boolean mtd_vars_is_managed_pointer(Method_Handle mh, unsigned idx) -{ - return false; -}; -Boolean mtd_ret_type_is_managed_pointer(Method_Signature_Handle msh) -{ - return false; -}; - -Boolean mtd_args_is_managed_pointer(Method_Signature_Handle msh, unsigned idx) -{ - return false; -}; - // The JIT info block is laid out as: // header // stack info @@ -77,15 +66,20 @@ return (size - sizeof(void *)); // skip the header } -// TODO: move both methods below to the base VMInterface level +void* +VMInterface::getTypeHandleFromVTable(void* vtHandle){ + return vtable_get_class((VTable_Handle)vtHandle); +} + + // TODO: free TLS key on JIT deinitilization uint32 -flagTLSSuspendRequestOffset(){ +VMInterface::flagTLSSuspendRequestOffset(){ return hythread_tls_get_request_offset(); } uint32 -flagTLSThreadStateOffset() { +VMInterface::flagTLSThreadStateOffset() { static hythread_tls_key_t key = 0; static size_t offset = 0; if (key == 0) { @@ -97,13 +91,13 @@ } ////////////////////////////////////////////////////////////////////////////// -///////////////////////// DrlVMTypeManager ///////////////////////////////////// +///////////////////////// VMTypeManager ///////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // // VM specific type manager // void* -DrlVMTypeManager::getBuiltinValueTypeVMTypeHandle(Type::Tag type) { +TypeManager::getBuiltinValueTypeVMTypeHandle(Type::Tag type) { switch (type) { case Type::Void: return class_get_class_of_primitive_type(VM_DATA_TYPE_VOID); case Type::Boolean: return class_get_class_of_primitive_type(VM_DATA_TYPE_BOOLEAN); @@ -127,144 +121,96 @@ return NULL; } +void +VMInterface::rewriteCodeBlock(Byte* codeBlock, Byte* newCode, size_t size) { + vm_patch_code_block(codeBlock, newCode, size); +} + void* -DrlVMTypeManager::getSystemObjectVMTypeHandle() { +VMInterface::getSystemObjectVMTypeHandle() { return get_system_object_class(); } void* -DrlVMTypeManager::getSystemClassVMTypeHandle() { +VMInterface::getSystemClassVMTypeHandle() { return get_system_class_class(); } void* -DrlVMTypeManager::getSystemStringVMTypeHandle() { +VMInterface::getSystemStringVMTypeHandle() { return get_system_string_class(); } void* -DrlVMTypeManager::getArrayVMTypeHandle(void* elemVMTypeHandle,bool isUnboxed) { +VMInterface::getArrayVMTypeHandle(void* elemVMTypeHandle,bool isUnboxed) { if (isUnboxed) return class_get_array_of_unboxed((Class_Handle) elemVMTypeHandle); return class_get_array_of_class((Class_Handle) elemVMTypeHandle); } const char* -DrlVMTypeManager::getTypeNameQualifier(void* vmTypeHandle) { +VMInterface::getTypeNameQualifier(void* vmTypeHandle) { return class_get_package_name((Class_Handle) vmTypeHandle); } void* -DrlVMTypeManager::getArrayElemVMTypeHandle(void* vmTypeHandle) { +VMInterface::getArrayElemVMTypeHandle(void* vmTypeHandle) { return class_get_array_element_class((Class_Handle) vmTypeHandle); } -const char* DrlVMTypeManager::getTypeName(void* vmTypeHandle) { +const char* VMInterface::getTypeName(void* vmTypeHandle) { return class_get_name((Class_Handle) vmTypeHandle); } bool -DrlVMTypeManager::isArrayOfPrimitiveElements(void* vmClassHandle) { +VMInterface::isArrayOfPrimitiveElements(void* vmClassHandle) { return type_info_is_primitive(class_get_element_type_info((Class_Handle) vmClassHandle))?true:false; } bool -DrlVMTypeManager::isEnumType(void* vmTypeHandle) { - return false; +VMInterface::isEnumType(void* vmTypeHandle) { + return class_is_enum((Class_Handle) vmTypeHandle); } bool -DrlVMTypeManager::isValueType(void* vmTypeHandle) { +VMInterface::isValueType(void* vmTypeHandle) { return class_is_primitive((Class_Handle) vmTypeHandle); } bool -DrlVMTypeManager::isLikelyExceptionType(void* vmTypeHandle) { +VMInterface::isLikelyExceptionType(void* vmTypeHandle) { return class_hint_is_exceptiontype((Class_Handle) vmTypeHandle)?true:false; } bool -DrlVMTypeManager::isVariableSizeType(void* vmTypeHandle) { - return isArrayType(vmTypeHandle); -} - -const char* -DrlVMTypeManager::getMethodName(MethodDesc* methodDesc) { - return methodDesc->getName(); -} - - -bool -DrlVMTypeManager::isSystemStringType(void* vmTypeHandle) { - // We should also be looking at namespace - if (vmTypeHandle == systemStringVMTypeHandle) - return true; - const char* name = getTypeName(vmTypeHandle); - if (systemStringVMTypeHandle == NULL && strcmp(name,"String") == 0) { - // Built-in System.String type - systemStringVMTypeHandle = vmTypeHandle; - return true; - } - return false; -} - -bool -DrlVMTypeManager::isSystemObjectType(void* vmTypeHandle) { - // We should also be looking at namespace - if (vmTypeHandle == systemObjectVMTypeHandle) - return true; - const char* name = getTypeName(vmTypeHandle); - if (systemObjectVMTypeHandle == NULL && strcmp(name,"Object") == 0) { - // Built-in System.Object type - systemObjectVMTypeHandle = vmTypeHandle; - return true; - } - return false; -} - -bool -DrlVMTypeManager::isSystemClassType(void* vmTypeHandle) { - // We should also be looking at namespace - if (vmTypeHandle == systemClassVMTypeHandle) - return true; - const char* name = getTypeName(vmTypeHandle); - if (systemClassVMTypeHandle == NULL && strcmp(name,"Class") == 0) { - // Built-in System.Class type - systemClassVMTypeHandle = vmTypeHandle; - return true; - } - return false; -} - -bool -DrlVMTypeManager::isBeforeFieldInit(void* vmTypeHandle) { +VMInterface::isBeforeFieldInit(void* vmTypeHandle) { return class_is_before_field_init((Class_Handle) vmTypeHandle)?true:false; } bool -DrlVMTypeManager::getClassFastInstanceOfFlag(void* vmTypeHandle) { +VMInterface::getClassFastInstanceOfFlag(void* vmTypeHandle) { return class_get_fast_instanceof_flag((Class_Handle) vmTypeHandle)?true:false; } int -DrlVMTypeManager::getClassDepth(void* vmTypeHandle) { +VMInterface::getClassDepth(void* vmTypeHandle) { return class_get_depth((Class_Handle) vmTypeHandle); } uint32 -DrlVMTypeManager::getArrayLengthOffset() { +VMInterface::getArrayLengthOffset() { return vector_length_offset(); } uint32 -DrlVMTypeManager::getArrayElemOffset(void* vmElemTypeHandle,bool isUnboxed) { +VMInterface::getArrayElemOffset(void* vmElemTypeHandle,bool isUnboxed) { if (isUnboxed) return vector_first_element_offset_unboxed((Class_Handle) vmElemTypeHandle); return vector_first_element_offset_class_handle((Class_Handle) vmElemTypeHandle); } bool -DrlVMTypeManager::isSubClassOf(void* vmTypeHandle1,void* vmTypeHandle2) { +VMInterface::isSubClassOf(void* vmTypeHandle1,void* vmTypeHandle2) { if (vmTypeHandle1 == (void*)(POINTER_SIZE_INT)0xdeadbeef || vmTypeHandle2 == (void*)(POINTER_SIZE_INT)0xdeadbeef ) { return false; @@ -273,262 +219,233 @@ } uint32 -DrlVMTypeManager::getUnboxedOffset(void* vmTypeHandle) { - assert(false); return 0; -} - -uint32 -DrlVMTypeManager::getBoxedSize(void * vmTypeHandle) { +VMInterface::getObjectSize(void * vmTypeHandle) { return class_get_boxed_data_size((Class_Handle) vmTypeHandle); } -uint32 -DrlVMTypeManager::getUnboxedSize(void* vmTypeHandle) { - assert(false); return 0; +void* VMInterface::getSuperTypeVMTypeHandle(void* vmTypeHandle) { + return class_get_super_class((Class_Handle)vmTypeHandle); } - -uint32 -DrlVMTypeManager::getUnboxedAlignment(void* vmTypeHandle) { - return class_get_alignment((Class_Handle) vmTypeHandle); +bool VMInterface::isArrayType(void* vmTypeHandle) { + return class_is_array((Class_Handle)vmTypeHandle)?true:false; } - -uint32 -DrlVMTypeManager::getUnboxedNumFields(void* vmTypeHandle) { - assert(0); - return 0; -} - -FieldDesc* -DrlVMTypeManager::getUnboxedFieldDesc(void* vmTypeHandle,uint32 index) { - assert(0); - return NULL; +bool VMInterface::isFinalType(void* vmTypeHandle) { + return class_property_is_final((Class_Handle)vmTypeHandle)?true:false; } - -Type* -DrlVMTypeManager::getUnderlyingType(void* enumVMTypeHandle) { - assert(false); return 0; +bool VMInterface::isInterfaceType(void* vmTypeHandle) { + return class_property_is_interface2((Class_Handle)vmTypeHandle)?true:false; } - -////////////////////////////////////////////////////////////////////////////// -///////////////////////// DrlVMMethodSignatureDesc ///////////////////////////// -////////////////////////////////////////////////////////////////////////////// -Type** -DrlVMMethodSignatureDesc::getParamTypes() { - if (paramTypes != NULL) - return paramTypes; - uint32 numParams = getNumParams(); - paramTypes = new (compilationInterface->getMemManager()) Type* [numParams]; - for (uint32 i=0; igetTypeFromDrlVMTypeHandle(typeHandle,isManagedPointer); +uint32 VMInterface::getVTableOffset() +{ + return object_get_vtable_offset(); } -Type* -DrlVMMethodSignatureDesc::getReturnType() { - bool isManagedPointer = - mtd_ret_type_is_managed_pointer(drlSigHandle)?true:false; - Type_Info_Handle typeHandle = method_ret_type_get_type_info(drlSigHandle); - return compilationInterface->getTypeFromDrlVMTypeHandle(typeHandle,isManagedPointer); +void* VMInterface::getTypeHandleFromAllocationHandle(void* vmAllocationHandle) +{ + return allocation_handle_get_class((Allocation_Handle)vmAllocationHandle); } + + ////////////////////////////////////////////////////////////////////////////// -///////////////////////// DrlVMMethodDesc ////////////////////////////////////// +///////////////////////// MethodDesc ////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -bool -DrlVMMethodDesc::isVarPinned(uint32 varIndex) { - return false; +uint32 +MethodDesc::getNumParams() const { + return method_args_get_number(methodSig); } -Type* -DrlVMMethodDesc::getVarType(uint32 varIndex) { - bool isManagedPointer = - mtd_vars_is_managed_pointer(drlMethod,varIndex)?true:false; - Type_Info_Handle typeHandle = method_vars_get_type_info(drlMethod,varIndex); - return compilationInterface->getTypeFromDrlVMTypeHandle(typeHandle,isManagedPointer); +Type* +MethodDesc::getParamType(uint32 paramIndex) const { + Type_Info_Handle typeHandle = method_args_get_type_info(methodSig,paramIndex); + return compilationInterface->getTypeFromDrlVMTypeHandle(typeHandle); } -NamedType* -DrlVMMethodDesc::getParentType() { - TypeManager& typeManager = compilationInterface->getTypeManager(); - Class_Handle parentClassHandle = method_get_class(drlMethod); - if (class_is_primitive(parentClassHandle)) - return typeManager.getValueType(parentClassHandle); - return typeManager.getObjectType(parentClassHandle); +Type* +MethodDesc::getReturnType() const { + Type_Info_Handle typeHandle = method_ret_type_get_type_info(methodSig); + return compilationInterface->getTypeFromDrlVMTypeHandle(typeHandle); } -unsigned -DrlVMMethodDesc::parseJavaHandlers(ExceptionCallback& callback) { - uint32 numHandlers = getNumHandlers(); - for (uint32 i=0; igetParentHandle(); + return class_get_cp_entry_signature(enclosingDrlVMClass, (unsigned short)methodToken); } +Method_Side_Effects +MethodDesc::getSideEffect() const { + return method_get_side_effects(drlMethod); +} + +void +MethodDesc::setSideEffect(Method_Side_Effects mse) { + method_set_side_effects(drlMethod, mse); +} + +void +MethodDesc::setNumExceptionHandler(uint32 numHandlers) { + method_set_num_target_handlers(drlMethod,getJitHandle(),numHandlers); +} + +void +MethodDesc::setExceptionHandlerInfo(uint32 exceptionHandlerNumber, + Byte* startAddr, + Byte* endAddr, + Byte* handlerAddr, + NamedType* exceptionType, + bool exceptionObjIsDead) { + void* exn_handle; + assert(exceptionType); + if (exceptionType->isSystemObject()) + exn_handle = NULL; + else + exn_handle = exceptionType->getRuntimeIdentifier(); + method_set_target_handler_info(drlMethod, + getJitHandle(), + exceptionHandlerNumber, + startAddr, + endAddr, + handlerAddr, + (Class_Handle) exn_handle, + exceptionObjIsDead ? TRUE : FALSE); + } + + ////////////////////////////////////////////////////////////////////////////// -///////////////////////// DrlVMFieldDesc /////////////////////////////////////// +///////////////////////// FieldDesc /////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// bool -DrlVMFieldDesc::isLiteral() { +FieldDesc::isLiteral() const { return field_is_literal(drlField)?true:false; } -bool -DrlVMFieldDesc::isUnmanagedStatic() { - return false; +Class_Handle FieldDesc::getParentHandle() const { + return field_get_class(drlField); } NamedType* -DrlVMFieldDesc::getParentType() { +TypeMemberDesc::getParentType() { TypeManager& typeManager = compilationInterface->getTypeManager(); - Class_Handle parentClassHandle = field_get_class(drlField); - if (class_is_primitive(parentClassHandle)) + Class_Handle parentClassHandle = getParentHandle(); + if (class_is_primitive(parentClassHandle)) { + assert(0); return typeManager.getValueType(parentClassHandle); + } return typeManager.getObjectType(parentClassHandle); } Type* -DrlVMFieldDesc::getFieldType() { +FieldDesc::getFieldType() { Type_Info_Handle typeHandle = field_get_type_info_of_field_value(drlField); - return compilationInterface->getTypeFromDrlVMTypeHandle(typeHandle,false); + return compilationInterface->getTypeFromDrlVMTypeHandle(typeHandle); } uint32 -DrlVMFieldDesc::getOffset() { - if(getParentType()->isObject()) { - return field_get_offset(drlField); - } - else { - assert(false); return 0; - } +FieldDesc::getOffset() const { + return field_get_offset(drlField); } ////////////////////////////////////////////////////////////////////////////// -//////////////////////////// DrlVMClassHierachyMethodIterator ////////////////// +//////////////////////////// ClassHierachyMethodIterator ////////////////// ////////////////////////////////////////////////////////////////////////////// + +ClassHierarchyMethodIterator::ClassHierarchyMethodIterator( + CompilationInterface& compilationInterface, ObjectType* objType, MethodDesc* methodDesc) + : compilationInterface(compilationInterface) +{ + valid = method_iterator_initialize(&iterator, methodDesc->getMethodHandle(), + (Class_Handle) objType->getVMTypeHandle()); +} + +bool ClassHierarchyMethodIterator::hasNext() const { + Method_Handle handle = method_iterator_get_current(&iterator); + return handle != NULL; +} + MethodDesc* -DrlVMClassHierarchyMethodIterator::getNext() { +ClassHierarchyMethodIterator::getNext() { MethodDesc* desc = compilationInterface.getMethodDesc(method_iterator_get_current(&iterator)); method_iterator_advance(&iterator); return desc; } - ////////////////////////////////////////////////////////////////////////////// -//////////////////////////// DrlVMCompilationInterface ///////////////////////// +//////////////////////////// CompilationInterface ///////////////////////// ////////////////////////////////////////////////////////////////////////////// -void -DrlVMCompilationInterface::hardAssert(const char *message, int line, const char *file) -{ - ::std::cerr << message << " at line " << line << " of file " << file << ::std::endl; - exit(1); -} - Type* -DrlVMCompilationInterface::getTypeFromDrlVMTypeHandle(Type_Info_Handle typeHandle) { - return getTypeFromDrlVMTypeHandle(typeHandle, false); -} - -Type* -DrlVMCompilationInterface::getTypeFromDrlVMTypeHandle(Type_Info_Handle typeHandle, - bool isManagedPointer) { +CompilationInterface::getTypeFromDrlVMTypeHandle(Type_Info_Handle typeHandle) { Type* type = NULL; - if (isManagedPointer) { - Type_Info_Handle pointedToTypeHandle = type_info_get_type_info(typeHandle); - Type* pointedToType = getTypeFromDrlVMTypeHandle(pointedToTypeHandle); - if (!pointedToType) - return NULL; - type = typeManager.getManagedPtrType(pointedToType); - } else if (type_info_is_void(typeHandle)) { + if (type_info_is_void(typeHandle)) { // void return type type = typeManager.getVoidType(); } else if (type_info_is_reference(typeHandle)) { @@ -549,8 +466,6 @@ if (!elemType) return NULL; type = typeManager.getArrayType(elemType); - } else if (type_info_is_general_array(typeHandle)) { - assert(0); } else { // should not get here assert(0); @@ -558,7 +473,7 @@ return type; } -VM_RT_SUPPORT DrlVMCompilationInterface::translateHelperId(RuntimeHelperId runtimeHelperId) { +VM_RT_SUPPORT CompilationInterface::translateHelperId(RuntimeHelperId runtimeHelperId) { VM_RT_SUPPORT vmHelperId = (VM_RT_SUPPORT)-1; switch (runtimeHelperId) { case Helper_NewObj_UsingVtable: vmHelperId = VM_RT_NEW_RESOLVED_USING_VTABLE_AND_SIZE; break; @@ -616,13 +531,13 @@ } void* -DrlVMCompilationInterface::getRuntimeHelperAddress(RuntimeHelperId runtimeHelperId) { +CompilationInterface::getRuntimeHelperAddress(RuntimeHelperId runtimeHelperId) { VM_RT_SUPPORT drlHelperId = translateHelperId(runtimeHelperId); return vm_get_rt_support_addr(drlHelperId); } void* -DrlVMCompilationInterface::getRuntimeHelperAddressForType(RuntimeHelperId runtimeHelperId, Type* type) { +CompilationInterface::getRuntimeHelperAddressForType(RuntimeHelperId runtimeHelperId, Type* type) { VM_RT_SUPPORT drlHelperId = translateHelperId(runtimeHelperId); Class_Handle handle = NULL; if (type != NULL && type->isNamedType()) @@ -632,45 +547,8 @@ return addr; } -CompilationInterface::MethodSideEffect -DrlVMCompilationInterface::getMethodHasSideEffect(MethodDesc *m) { - Method_Side_Effects mse = method_get_side_effects(((DrlVMMethodDesc*)m)->getDrlVMMethod()); - - switch (mse) { - case MSE_True: return CompilationInterface::MSE_YES; - case MSE_False: return CompilationInterface::MSE_NO; - case MSE_Unknown: return CompilationInterface::MSE_UNKNOWN; - case MSE_True_Null_Param: return CompilationInterface::MSE_NULL_PARAM; - default: - assert(0); - return CompilationInterface::MSE_UNKNOWN; - } -} - -void -DrlVMCompilationInterface::setMethodHasSideEffect(MethodDesc *m, MethodSideEffect mse) { - Method_Handle handle = ((DrlVMMethodDesc*)m)->getDrlVMMethod(); - - switch (mse) { - case CompilationInterface::MSE_YES: - method_set_side_effects(handle, MSE_True); - break; - case CompilationInterface::MSE_NO: - method_set_side_effects(handle, MSE_False); - break; - case CompilationInterface::MSE_UNKNOWN: - method_set_side_effects(handle, MSE_Unknown); - break; - case CompilationInterface::MSE_NULL_PARAM: - method_set_side_effects(handle, MSE_True_Null_Param); - break; - default: - assert(0); - } -} - CompilationInterface::VmCallingConvention -DrlVMCompilationInterface::getRuntimeHelperCallingConvention(RuntimeHelperId id) { +CompilationInterface::getRuntimeHelperCallingConvention(RuntimeHelperId id) { switch(id) { case Helper_NewMultiArray: case Helper_WriteBarrier: @@ -687,63 +565,21 @@ } bool -DrlVMCompilationInterface::compileMethod(MethodDesc *method) { +CompilationInterface::compileMethod(MethodDesc *method) { if (Log::isEnabled()) { Log::out() << "Jitrino requested compilation of " << method->getParentType()->getName() << "::" << method->getName() << method->getSignatureString() << ::std::endl; } - JIT_Result res = vm_compile_method(getJitHandle(), ((DrlVMMethodDesc*)method)->getDrlVMMethod()); + JIT_Result res = vm_compile_method(getJitHandle(), method->getMethodHandle()); return res == JIT_SUCCESS ? true : false; } -void -DrlVMCompilationInterface::setNumExceptionHandler(uint32 numHandlers) { - method_set_num_target_handlers(methodToCompile->getDrlVMMethod(),getJitHandle(), - numHandlers); -} - -void -DrlVMCompilationInterface::setExceptionHandlerInfo(uint32 exceptionHandlerNumber, - Byte* startAddr, - Byte* endAddr, - Byte* handlerAddr, - NamedType* exceptionType, - bool exceptionObjIsDead) { - void* exn_handle; - assert(exceptionType); - if (exceptionType->isSystemObject()) - exn_handle = NULL; - else - exn_handle = exceptionType->getRuntimeIdentifier(); - method_set_target_handler_info(methodToCompile->getDrlVMMethod(), - getJitHandle(), - exceptionHandlerNumber, - startAddr, - endAddr, - handlerAddr, - (Class_Handle) exn_handle, - exceptionObjIsDead ? TRUE : FALSE); -} - -// token resolution methods -MethodSignatureDesc* -DrlVMCompilationInterface::resolveSignature(MethodDesc* enclosingMethodDesc, - uint32 sigToken) { - assert(0); - return NULL; -} - -Class_Handle -DrlVMCompilationInterface::methodGetClass(MethodDesc* method) { - return method_get_class(((DrlVMMethodDesc*)method)->getDrlVMMethod()); -} - FieldDesc* -DrlVMCompilationInterface::resolveField(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveField(MethodDesc* enclosingMethodDesc, uint32 fieldToken, bool putfield) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Field_Handle resolvedField = resolve_nonstatic_field(compileHandle,enclosingDrlVMClass,fieldToken,putfield); @@ -752,7 +588,7 @@ } FieldDesc* -DrlVMCompilationInterface::resolveFieldByIndex(NamedType* klass, int index, NamedType **fieldType) { +CompilationInterface::resolveFieldByIndex(NamedType* klass, int index, NamedType **fieldType) { Class_Handle ch = (Class_Handle) klass->getVMTypeHandle(); Field_Handle fh; @@ -764,9 +600,9 @@ } FieldDesc* -DrlVMCompilationInterface::resolveStaticField(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveStaticField(MethodDesc* enclosingMethodDesc, uint32 fieldToken, bool putfield) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Field_Handle resolvedField = resolve_static_field(compileHandle,enclosingDrlVMClass,fieldToken,putfield); @@ -775,15 +611,9 @@ } MethodDesc* -DrlVMCompilationInterface::resolveMethod(MethodDesc* enclosingMethodDesc, - uint32 methodToken) { - assert(false); return 0; -} - -MethodDesc* -DrlVMCompilationInterface::resolveVirtualMethod(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveVirtualMethod(MethodDesc* enclosingMethodDesc, uint32 methodToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Method_Handle resolvedMethod = resolve_virtual_method(compileHandle,enclosingDrlVMClass,methodToken); @@ -792,9 +622,9 @@ } MethodDesc* -DrlVMCompilationInterface::resolveSpecialMethod(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveSpecialMethod(MethodDesc* enclosingMethodDesc, uint32 methodToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Method_Handle resolvedMethod = resolve_special_method(compileHandle,enclosingDrlVMClass,methodToken); @@ -803,9 +633,9 @@ } MethodDesc* -DrlVMCompilationInterface::resolveStaticMethod(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveStaticMethod(MethodDesc* enclosingMethodDesc, uint32 methodToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Method_Handle resolvedMethod = resolve_static_method(compileHandle,enclosingDrlVMClass,methodToken); @@ -814,9 +644,9 @@ } MethodDesc* -DrlVMCompilationInterface::resolveInterfaceMethod(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveInterfaceMethod(MethodDesc* enclosingMethodDesc, uint32 methodToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Method_Handle resolvedMethod = resolve_interface_method(compileHandle,enclosingDrlVMClass,methodToken); @@ -825,9 +655,9 @@ } NamedType* -DrlVMCompilationInterface::resolveNamedType(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveNamedType(MethodDesc* enclosingMethodDesc, uint32 typeToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Class_Handle ch = resolve_class(compileHandle,enclosingDrlVMClass,typeToken); @@ -838,9 +668,9 @@ } NamedType* -DrlVMCompilationInterface::resolveNamedTypeNew(MethodDesc* enclosingMethodDesc, +CompilationInterface::resolveNamedTypeNew(MethodDesc* enclosingMethodDesc, uint32 typeToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Class_Handle ch = resolve_class_new(compileHandle,enclosingDrlVMClass,typeToken); @@ -851,9 +681,9 @@ } Type* -DrlVMCompilationInterface::getFieldType(MethodDesc* enclosingMethodDesc, +CompilationInterface::getFieldType(MethodDesc* enclosingMethodDesc, uint32 entryCPIndex) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Java_Type drlType = (Java_Type)class_get_cp_field_type(enclosingDrlVMClass, (unsigned short)entryCPIndex); switch (drlType) { case JAVA_TYPE_BOOLEAN: return typeManager.getBooleanType(); @@ -874,32 +704,18 @@ assert(0); return NULL; } -const char* -DrlVMCompilationInterface::methodSignatureString(MethodDesc* enclosingMethodDesc, - uint32 methodToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); - return class_get_cp_entry_signature(enclosingDrlVMClass, (unsigned short)methodToken); -} void* -DrlVMCompilationInterface::loadStringObject(MethodDesc* enclosingMethodDesc, +CompilationInterface::loadStringObject(MethodDesc* enclosingMethodDesc, uint32 stringToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); return class_get_const_string_intern_addr(enclosingDrlVMClass,stringToken); } -// -// Note: This is CLI only but temporarily here for Java also -// -void* -DrlVMCompilationInterface::loadToken(MethodDesc* enclosingMethodDesc,uint32 token) { - assert(false); return 0; -} - Type* -DrlVMCompilationInterface::getConstantType(MethodDesc* enclosingMethodDesc, +CompilationInterface::getConstantType(MethodDesc* enclosingMethodDesc, uint32 constantToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); Java_Type drlType = (Java_Type)class_get_const_type(enclosingDrlVMClass,constantToken); switch (drlType) { case JAVA_TYPE_STRING: return typeManager.getSystemStringType(); @@ -915,118 +731,63 @@ } const void* -DrlVMCompilationInterface::getConstantValue(MethodDesc* enclosingMethodDesc, +CompilationInterface::getConstantValue(MethodDesc* enclosingMethodDesc, uint32 constantToken) { - Class_Handle enclosingDrlVMClass = methodGetClass(enclosingMethodDesc); + Class_Handle enclosingDrlVMClass = enclosingMethodDesc->getParentHandle(); return class_get_const_addr(enclosingDrlVMClass,constantToken); } MethodDesc* -DrlVMCompilationInterface::getOverriddenMethod(NamedType* type, MethodDesc *methodDesc) { +CompilationInterface::getOverriddenMethod(NamedType* type, MethodDesc *methodDesc) { Method_Handle m = method_find_overridden_method((Class_Handle) type->getVMTypeHandle(), - ((DrlVMMethodDesc*)methodDesc)->getDrlVMMethod()); + methodDesc->getMethodHandle()); if (!m) return NULL; return getMethodDesc(m); } -ClassHierarchyIterator* -DrlVMCompilationInterface::getClassHierarchyIterator(ObjectType* baseType) { - DrlVMClassHierarchyIterator* iterator = new (getMemManager()) DrlVMClassHierarchyIterator(getTypeManager(), baseType); - return iterator->isValid() ? iterator : NULL; -} - ClassHierarchyMethodIterator* -DrlVMCompilationInterface::getClassHierarchyMethodIterator(ObjectType* baseType, MethodDesc* methodDesc) { - DrlVMClassHierarchyMethodIterator* iterator = new (getMemManager()) DrlVMClassHierarchyMethodIterator(*this, baseType, methodDesc); - return iterator->isValid() ? iterator : NULL; +CompilationInterface::getClassHierarchyMethodIterator(ObjectType* baseType, MethodDesc* methodDesc) { + return new (getMemManager()) ClassHierarchyMethodIterator(*this, baseType, methodDesc); } -// accessors for method info, code and data -Byte* DrlVMCompilationInterface::getInfoBlock(MethodDesc* methodDesc) { - Method_Handle drlMethod = ((DrlVMMethodDesc*)methodDesc)->getDrlVMMethod(); - return methodGetStacknGCInfoBlock(drlMethod, getJitHandle()); -} - -uint32 DrlVMCompilationInterface::getInfoBlockSize(MethodDesc* methodDesc) { - Method_Handle drlMethod = ((DrlVMMethodDesc*)methodDesc)->getDrlVMMethod(); - return methodGetStacknGCInfoBlockSize(drlMethod,getJitHandle()); -} - -Byte* DrlVMCompilationInterface::getCodeBlockAddress(MethodDesc* methodDesc, int32 id) { - Method_Handle drlMethod = ((DrlVMMethodDesc*)methodDesc)->getDrlVMMethod(); - return method_get_code_block_addr_jit_new(drlMethod,getJitHandle(),id); -} - -uint32 DrlVMCompilationInterface::getCodeBlockSize(MethodDesc* methodDesc, int32 id) { - Method_Handle drlMethod = ((DrlVMMethodDesc*)methodDesc)->getDrlVMMethod(); - return method_get_code_block_size_jit_new(drlMethod,getJitHandle(),id); -} - -void DrlVMCompilationInterface::setNotifyWhenClassIsExtended(ObjectType * type, +void CompilationInterface::setNotifyWhenClassIsExtended(ObjectType * type, void * callbackData) { void * typeHandle = type->getVMTypeHandle(); vm_register_jit_extended_class_callback(getJitHandle(), (Class_Handle) typeHandle,callbackData); } -void DrlVMCompilationInterface::setNotifyWhenMethodIsOverridden(MethodDesc * methodDesc, +void CompilationInterface::setNotifyWhenMethodIsOverridden(MethodDesc * methodDesc, void * callbackData) { - Method_Handle drlMethod = ((DrlVMMethodDesc *)methodDesc)->getDrlVMMethod(); + Method_Handle drlMethod = methodDesc->getMethodHandle(); vm_register_jit_overridden_method_callback(getJitHandle(), drlMethod, callbackData); } -void DrlVMCompilationInterface::setNotifyWhenMethodIsRecompiled(MethodDesc * methodDesc, +void CompilationInterface::setNotifyWhenMethodIsRecompiled(MethodDesc * methodDesc, void * callbackData) { - Method_Handle drlMethod = ((DrlVMMethodDesc *)methodDesc)->getDrlVMMethod(); + Method_Handle drlMethod = methodDesc->getMethodHandle(); vm_register_jit_recompiled_method_callback(getJitHandle(),drlMethod,callbackData); } - -bool DrlVMCompilationInterface::mayInlineObjectSynchronization(ObjectSynchronizationInfo & syncInfo) { - unsigned threadIdReg, syncHeaderOffset, syncHeaderWidth, lockOwnerOffset, lockOwnerWidth; - Boolean jitClearsCcv; - Boolean mayInline = - jit_may_inline_object_synchronization(&threadIdReg, &syncHeaderOffset, &syncHeaderWidth, - &lockOwnerOffset, &lockOwnerWidth, &jitClearsCcv); - if (mayInline == TRUE) { - syncInfo.threadIdReg = threadIdReg; - syncInfo.syncHeaderOffset = syncHeaderOffset; - syncInfo.syncHeaderWidth = syncHeaderWidth; - syncInfo.lockOwnerOffset = lockOwnerOffset; - syncInfo.lockOwnerWidth = lockOwnerWidth; - syncInfo.jitClearsCcv = (jitClearsCcv == TRUE); - } - return mayInline == TRUE; -} - -void DrlVMCompilationInterface::sendCompiledMethodLoadEvent(MethodDesc* methodDesc, MethodDesc* outerDesc, +void CompilationInterface::sendCompiledMethodLoadEvent(MethodDesc* methodDesc, MethodDesc* outerDesc, uint32 codeSize, void* codeAddr, uint32 mapLength, AddrLocation* addrLocationMap, void* compileInfo) { - Method_Handle method = (Method_Handle)getRuntimeMethodHandle(methodDesc); - Method_Handle outer = (Method_Handle)getRuntimeMethodHandle(outerDesc); + Method_Handle method = methodDesc->getMethodHandle(); + Method_Handle outer = outerDesc->getMethodHandle(); compiled_method_load(method, codeSize, codeAddr, mapLength, addrLocationMap, compileInfo, outer); } -bool DrlVMDataInterface::areReferencesCompressed() { - return (vm_references_are_compressed() != 0); -} - -void * DrlVMDataInterface::getHeapBase() { +void * VMInterface::getHeapBase() { return vm_heap_base_address(); } -void * DrlVMDataInterface::getHeapCeiling() { +void * VMInterface::getHeapCeiling() { return vm_heap_ceiling_address(); } -void DrlVMBinaryRewritingInterface::rewriteCodeBlock(Byte* codeBlock, Byte* newCode, size_t size) { - vm_patch_code_block(codeBlock, newCode, size); -} - - -ObjectType * DrlVMCompilationInterface::resolveClassUsingBootstrapClassloader( const char * klassName ) { +ObjectType * CompilationInterface::resolveClassUsingBootstrapClassloader( const char * klassName ) { Class_Handle cls = class_load_class_by_name_using_bootstrap_class_loader(klassName); if( NULL == cls ) { return NULL; @@ -1035,7 +796,7 @@ }; -MethodDesc* DrlVMCompilationInterface::resolveMethod( ObjectType* klass, const char * methodName, const char * methodSig) { +MethodDesc* CompilationInterface::resolveMethod( ObjectType* klass, const char * methodName, const char * methodSig) { Class_Handle cls = (Class_Handle)klass->getVMTypeHandle(); assert( NULL != cls ); Method_Handle mh = class_lookup_method_recursively( cls, methodName, methodSig); @@ -1046,14 +807,14 @@ }; JIT_Handle -DrlVMCompilationInterface::getJitHandle() const { +CompilationInterface::getJitHandle() const { return getCompilationContext()->getCurrentJITContext()->getJitHandle(); } -NamedType* DrlVMMethodDesc::getThrowType(uint32 i) { +NamedType* MethodDesc::getThrowType(uint32 i) { assert(i<=method_number_throws(drlMethod)); Class_Handle ch = method_get_throws(drlMethod, i); assert(ch); @@ -1061,8 +822,76 @@ return res; } -bool DrlVMMethodDesc::hasAnnotation(NamedType* type) { +bool MethodDesc::hasAnnotation(NamedType* type) const { return method_has_annotation(drlMethod, (Class_Handle)type->getVMTypeHandle()); } +void FieldDesc::printFullName(::std::ostream &os) { + os<getName()<<"::"<getName()<<"::"<lookup(field); +if (fieldDesc == NULL) { +fieldDesc = new (memManager) +FieldDesc(field,this,nextMemberId++); +fieldDescs->insert(field,fieldDesc); +} +return fieldDesc; +} + +MethodDesc* CompilationInterface:: getMethodDesc(Method_Handle method, JIT_Handle jit) { +assert(method); +MethodDesc* methodDesc = methodDescs->lookup(method); +if (methodDesc == NULL) { +methodDesc = new (memManager) +MethodDesc(method, jit, this, nextMemberId++); +methodDescs->insert(method,methodDesc); +} +return methodDesc; +} + +CompilationInterface::CompilationInterface(Compile_Handle c, + Method_Handle m, JIT_Handle jit, + MemoryManager& mm, OpenMethodExecutionParams& comp_params, + CompilationContext* cc, TypeManager& tpm) : +compilationContext(cc), memManager(mm), +typeManager(tpm), compilation_params(comp_params) +{ + fieldDescs = new (mm) PtrHashTable(mm,32); + methodDescs = new (mm) PtrHashTable(mm,32); + compileHandle = c; + nextMemberId = 0; + methodToCompile = NULL; + methodToCompile = getMethodDesc(m, jit); + flushToZeroAllowed = false; +} + +void CompilationInterface::lockMethodData(void) { g_compileLock.lock(); } + +void CompilationInterface::unlockMethodData(void) { g_compileLock.unlock(); } + +Byte* CompilationInterface::allocateCodeBlock(size_t size, size_t alignment, CodeBlockHeat heat, int32 id, +bool simulate) { + return method_allocate_code_block(methodToCompile->getMethodHandle(), getJitHandle(), + size, alignment, heat, id, simulate ? CAA_Simulate : CAA_Allocate); +} +Byte* CompilationInterface::allocateDataBlock(size_t size, size_t alignment) { + return method_allocate_data_block(methodToCompile->getMethodHandle(),getJitHandle(),size, alignment); +} +Byte* CompilationInterface::allocateInfoBlock(size_t size) { + size += sizeof(void *); + Byte *addr = method_allocate_info_block(methodToCompile->getMethodHandle(),getJitHandle(),size); + return (addr + sizeof(void *)); +} +Byte* CompilationInterface::allocateJITDataBlock(size_t size, size_t alignment) { + return method_allocate_jit_data_block(methodToCompile->getMethodHandle(),getJitHandle(),size, alignment); +} +MethodDesc* CompilationInterface::getMethodDesc(Method_Handle method) { + return getMethodDesc(method, getJitHandle()); +} + } //namespace Jitrino Index: vm/jitrino/src/vm/drl/DrlEMInterface.h =================================================================== --- vm/jitrino/src/vm/drl/DrlEMInterface.h (revision 523181) +++ vm/jitrino/src/vm/drl/DrlEMInterface.h (working copy) @@ -1,115 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* COPYRIGHT_NOTICE */ - -/** -* @author Mikhail Y. Fursov -* @version $Revision$ -*/ - -#ifndef _DRLEMINTERFACE_H_ -#define _DRLEMINTERFACE_H_ - -#include "EMInterface.h" - -namespace Jitrino { - -class DrlProfilingInterface : public ProfilingInterface { -public: - DrlProfilingInterface(EM_Handle _em, JIT_Handle _jit, EM_ProfileAccessInterface* emProfileAccess) - : emHandle(_em), ebPCHandle(NULL), edgePCHandle(NULL), valuePCHandle(NULL), jitHandle(_jit), profileAccessInterface(emProfileAccess), - jitRole(JITProfilingRole_USE), profilingEnabled(false){} - - PC_Handle getPCHandle(ProfileType type) const; - virtual EM_ProfileAccessInterface* getEMProfileAccessInterface() const { return profileAccessInterface; } - - virtual MethodProfile* getMethodProfile(MemoryManager& mm, ProfileType type, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const; - virtual Method_Profile_Handle getMethodProfileHandle(ProfileType type, MethodDesc& md) const; - virtual bool hasMethodProfile(ProfileType type, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const; - virtual uint32 getProfileMethodCount(MethodDesc& md, JITProfilingRole role = JITProfilingRole_USE) const; - - virtual bool enableProfiling(PC_Handle pc, JITProfilingRole role); - virtual bool isProfilingEnabled(ProfileType pcType, JITProfilingRole jitRole) const ; - - virtual EntryBackedgeMethodProfile* createEBMethodProfile(MemoryManager& mm, MethodDesc& md); - virtual bool isEBProfilerInSyncMode() const; - virtual PC_Callback_Fn* getEBProfilerSyncModeCallback() const; - - virtual EdgeMethodProfile* createEdgeMethodProfile(MemoryManager& mm, MethodDesc& md, uint32 numEdgeCounters, uint32* counterKeys, uint32 checkSum); - - virtual uint32 getMethodEntryThreshold() const; - virtual uint32 getBackedgeThreshold() const; - - // value profiler - virtual ValueMethodProfile* createValueMethodProfile (MemoryManager& mm, MethodDesc& md, uint32 numKeys, uint32* Keys); - -private: - EM_Handle emHandle; - // Various types of the profile collectors - PC_Handle ebPCHandle, edgePCHandle, valuePCHandle; - // ProfileType pcType; - JIT_Handle jitHandle; - EM_ProfileAccessInterface* profileAccessInterface; - // Only one role supported at one time - JITProfilingRole jitRole; - // There is only one flag so edge and value profile may work only simultaneously - // TODO: Better solution is needed when we want to have independent profiles - bool profilingEnabled; -}; - -class DrlEntryBackedgeMethodProfile : public EntryBackedgeMethodProfile { -public: - DrlEntryBackedgeMethodProfile(Method_Profile_Handle mph, MethodDesc& md, uint32* _entryCounter, uint32 *_backedgeCounter) - : EntryBackedgeMethodProfile(mph, md), entryCounter(_entryCounter), backedgeCounter(_backedgeCounter){} - - virtual uint32 getEntryExecCount() const {return *entryCounter;} - virtual uint32 getBackedgeExecCount() const {return *backedgeCounter;} - virtual uint32* getEntryCounter() const {return entryCounter;} - virtual uint32* getBackedgeCounter() const {return backedgeCounter;} - -private: - uint32* entryCounter; - uint32* backedgeCounter; -}; - - -class DrlEdgeMethodProfile : public EdgeMethodProfile { -public: - DrlEdgeMethodProfile (Method_Profile_Handle handle, MethodDesc& md, EM_ProfileAccessInterface* profileAccessInterface); - virtual uint32 getNumCounters() const; - virtual uint32 getCheckSum() const; - virtual uint32* getEntryCounter() const; - virtual uint32* getCounter(uint32 key) const ; - -private: - EM_ProfileAccessInterface* profileAccessInterface; - -}; - -class DrlValueMethodProfile: public ValueMethodProfile { -public: - DrlValueMethodProfile (Method_Profile_Handle handle, MethodDesc& md, EM_ProfileAccessInterface* profileAccessInterface); - virtual POINTER_SIZE_INT getTopValue(uint32 instructionKey) const; - virtual void dumpValues(std::ostream& os) const; -private: - EM_ProfileAccessInterface* profileAccessInterface; - -}; - - -} -#endif Index: vm/jitrino/src/vm/drl/DrlJITInterface.cpp =================================================================== --- vm/jitrino/src/vm/drl/DrlJITInterface.cpp (revision 523181) +++ vm/jitrino/src/vm/drl/DrlJITInterface.cpp (working copy) @@ -25,10 +25,10 @@ #include #endif - +#include "Type.h" #include "Jitrino.h" -#include "DrlVMInterface.h" -#include "DrlEMInterface.h" +#include "VMInterface.h" +#include "EMInterface.h" #include "MemoryEstimates.h" #include "Log.h" #include "PMF.h" @@ -38,6 +38,8 @@ #include "jit_export.h" #include "jit_export_jpda.h" #include "open/types.h" + +#define LOG_DOMAIN "jitrino" #include "cxxlog.h" #include @@ -131,7 +133,7 @@ { JITInstanceContext* jitContext = Jitrino::getJITInstanceContext(jit); MemoryManager& mm = Jitrino::getGlobalMM(); - DrlProfilingInterface* pi = new (mm) DrlProfilingInterface(em, jit, pc_interface); + ProfilingInterface* pi = new (mm) ProfilingInterface(em, jit, pc_interface); jitContext->setProfilingInterface(pi); } @@ -197,10 +199,8 @@ Method_Handle recompiled_method, void *callback_data) { - DrlVMBinaryRewritingInterface binaryRewritingInterface; - DrlVMMethodDesc methodDesc(recompiled_method); - bool res = Jitrino::RecompiledMethodEvent(binaryRewritingInterface, - &methodDesc,callback_data); + MethodDesc methodDesc(recompiled_method, NULL); + bool res = Jitrino::RecompiledMethodEvent(&methodDesc,callback_data); return (res ? TRUE : FALSE); } @@ -241,8 +241,9 @@ JITInstanceContext* jitContext = Jitrino::getJITInstanceContext(jitHandle); assert(jitContext!= NULL); - DrlVMCompilationInterface compilationInterface(compilation, method_handle, jit, - memManager, compilation_params, NULL); + TypeManager typeManager(memManager); typeManager.init(); + CompilationInterface compilationInterface(compilation, method_handle, jit, + memManager, compilation_params, NULL, typeManager); CompilationContext cs(memManager, &compilationInterface, jitContext); compilationInterface.setCompilationContext(&cs); @@ -348,7 +349,7 @@ return; } #endif - DrlVMMethodDesc methodDesc(method, jit); + MethodDesc methodDesc(method, jit); Jitrino::UnwindStack(&methodDesc, context, context->is_ip_past == FALSE); } @@ -372,8 +373,8 @@ } #endif - DrlVMMethodDesc methodDesc(method, jit); - DrlVMGCInterface gcInterface(enum_handle); + MethodDesc methodDesc(method, jit); + GCInterface gcInterface(enum_handle); Jitrino::GetGCRootSet(&methodDesc, &gcInterface, context, context->is_ip_past == FALSE); } @@ -413,7 +414,7 @@ JITEXPORT Boolean JIT_can_enumerate(JIT_Handle jit, Method_Handle method, NativeCodePtr eip) { - DrlVMMethodDesc methodDesc(method, jit); + MethodDesc methodDesc(method, jit); bool result = Jitrino::CanEnumerate(&methodDesc, eip); return (result ? TRUE : FALSE); } @@ -454,7 +455,7 @@ } #endif - DrlVMMethodDesc methodDesc(method, jit); + MethodDesc methodDesc(method, jit); Jitrino::FixHandlerContext(&methodDesc, context, context->is_ip_past == FALSE); } @@ -469,7 +470,7 @@ return Jet::rt_get_address_of_this(jit, method, context); } #endif - DrlVMMethodDesc methodDesc(method, jit); + MethodDesc methodDesc(method, jit); return Jitrino::GetAddressOfThis(&methodDesc, context, context->is_ip_past == FALSE); } @@ -522,11 +523,7 @@ #endif } #endif - DrlVMDataInterface dataIntf; - if (dataIntf.areReferencesCompressed()) - return true; - else - return false; + return (vm_references_are_compressed() != 0); } extern "C" @@ -540,8 +537,8 @@ class_get_name(method_get_class(method)) << "." << method_get_name(method) << ")" << ::std::endl; } - DrlVMMethodDesc methodDesc(method, jit); - DrlVMThreadDumpEnumerator gcInterface; + MethodDesc methodDesc(method, jit); + ThreadDumpEnumerator gcInterface; Jitrino::GetGCRootSet(&methodDesc, &gcInterface, context, context->is_ip_past == FALSE); } @@ -563,7 +560,7 @@ } #endif - DrlVMMethodDesc methDesc(method, jit); + MethodDesc methDesc(method, jit); uint64* ncAddr = (uint64*) native_pc; if (Jitrino::GetNativeLocationForBc(&methDesc, bc_pc, ncAddr)) { @@ -584,7 +581,7 @@ } #endif - DrlVMMethodDesc methDesc(method, jit); + MethodDesc methDesc(method, jit); POINTER_SIZE_INT ncAddr = (POINTER_SIZE_INT) native_pc; if (Jitrino::GetBcLocationForNative(&methDesc, (uint64)ncAddr, bc_pc)) { return EXE_ERROR_NONE; @@ -624,3 +621,4 @@ } //namespace Jitrino + Index: vm/jitrino/src/vm/drl/DrlVMInterface.h =================================================================== --- vm/jitrino/src/vm/drl/DrlVMInterface.h (revision 523181) +++ vm/jitrino/src/vm/drl/DrlVMInterface.h (working copy) @@ -1,690 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author Intel, Mikhail Y. Fursov - * @version $Revision: 1.30.12.3.4.4 $ - */ - -#ifndef _DRLVMINTERFACEIMPL_H_ -#define _DRLVMINTERFACEIMPL_H_ - -#include "Type.h" -#include "VMInterface.h" -#include "jit_export.h" -#include "jit_import.h" -#include "jit_runtime_support.h" -#include "jit_intf.h" -#include "mkernel.h" - -#include -#include - -namespace Jitrino { - -/** - * @brief A lock used to protect method's data in multi-threaded compilation. - */ -extern Mutex g_compileLock; - -// -// forward class definitions -// -class DrlVMCompilationInterface; - -uint32 flagTLSSuspendRequestOffset(); -uint32 flagTLSThreadStateOffset(); - -class DrlVMTypeManager : public TypeManager { -public: - DrlVMTypeManager(MemoryManager& mm) : TypeManager(mm) { - systemObjectVMTypeHandle = systemStringVMTypeHandle = NULL; - } - // - // VM specific methods for TypeDesc - // - void* getBuiltinValueTypeVMTypeHandle(Type::Tag); - void* getSystemObjectVMTypeHandle(); - void* getSystemClassVMTypeHandle(); - void* getSystemStringVMTypeHandle(); - void* getArrayVMTypeHandle(void* elemVMTypeHandle,bool isUnboxed); - const char* getTypeName(void* vmTypeHandle); - const char* getTypeNameQualifier(void* vmTypeHandle); - void* getSuperTypeVMTypeHandle(void* vmTypeHandle) { - return class_get_super_class((Class_Handle)vmTypeHandle); - } - const char* getMethodName(MethodDesc*); - void* getArrayElemVMTypeHandle(void* vmTypeHandle); - bool isArrayType(void* vmTypeHandle) { - return class_is_array((Class_Handle)vmTypeHandle)?true:false; - } - bool isArrayOfPrimitiveElements(void* vmTypeHandle); - bool isEnumType(void* vmTypeHandle); - bool isValueType(void* vmTypeHandle); - bool isLikelyExceptionType(void* vmTypeHandle); - bool isVariableSizeType(void* vmTypeHandle); - bool isFinalType(void* vmTypeHandle) { - return class_property_is_final((Class_Handle)vmTypeHandle)?true:false; - } - bool isInterfaceType(void* vmTypeHandle) { - return class_property_is_interface2((Class_Handle)vmTypeHandle)?true:false; - } - bool isAbstractType(void* vmTypeHandle) { - return class_property_is_abstract((Class_Handle)vmTypeHandle)?true:false; - } - bool isSystemStringType(void* vmTypeHandle); - bool isSystemObjectType(void* vmTypeHandle); - bool isSystemClassType(void* vmTypeHandle); - bool isBeforeFieldInit(void* vmTypeHandle); - bool getClassFastInstanceOfFlag(void* vmTypeHandle); - int getClassDepth(void* vmTypeHandle); - bool needsInitialization(void* vmTypeHandle) { - return class_needs_initialization((Class_Handle)vmTypeHandle)?true:false; - } - bool isFinalizable(void* vmTypeHandle) { - return class_is_finalizable((Class_Handle)vmTypeHandle)?true:false; - } - bool isInitialized(void* vmTypeHandle) { - return class_is_initialized((Class_Handle)vmTypeHandle)?true:false; - } - void* getVTable(void* vmTypeHandle) { - return (void *) class_get_vtable((Class_Handle)vmTypeHandle); - } - - // - // In DRL, these are the same. - // - void* getRuntimeClassHandle(void* vmTypeHandle) { - return vmTypeHandle; - } - - // - // Allocation handle to be used with calls to runtime support functions for - // object allocation - // - void* getAllocationHandle(void* vmTypeHandle) { - return (void *) class_get_allocation_handle((Class_Handle) vmTypeHandle); - } - - uint32 getVTableOffset() - { - return object_get_vtable_offset(); - } - - void* getTypeHandleFromAllocationHandle(void* vmAllocationHandle) - { - return allocation_handle_get_class((Allocation_Handle)vmAllocationHandle); - } - - - bool isSubClassOf(void* vmTypeHandle1,void* vmTypeHandle2); - uint32 getUnboxedOffset(void* vmTypeHandle); - uint32 getArrayElemOffset(void* vmElemTypeHandle,bool isUnboxed); - uint32 getBoxedSize(void * vmTypeHandle); - uint32 getUnboxedSize(void* vmTypeHandle); - uint32 getUnboxedAlignment(void* vmTypeHandle); - uint32 getUnboxedNumFields(void* vmTypeHandle); - FieldDesc* getUnboxedFieldDesc(void* vmTypeHandle,uint32 index); - uint32 getArrayLengthOffset(); - Type* getUnderlyingType(void* enumVMTypeHandle); - - Type* getTypeFromPrimitiveDrlVMDataType(VM_Data_Type drlDataType) { - switch (drlDataType) { - case VM_DATA_TYPE_INT8: return getInt8Type(); - case VM_DATA_TYPE_UINT8: return getUInt8Type(); - case VM_DATA_TYPE_INT16: return getInt16Type(); - case VM_DATA_TYPE_UINT16: return getUInt16Type(); - case VM_DATA_TYPE_INT32: return getInt32Type(); - case VM_DATA_TYPE_UINT32: return getUInt32Type(); - case VM_DATA_TYPE_INT64: return getInt64Type(); - case VM_DATA_TYPE_UINT64: return getUInt64Type(); - case VM_DATA_TYPE_INTPTR: return getIntPtrType(); - case VM_DATA_TYPE_UINTPTR: return getUIntPtrType(); - case VM_DATA_TYPE_F8: return getDoubleType(); - case VM_DATA_TYPE_F4: return getSingleType(); - case VM_DATA_TYPE_BOOLEAN: return getBooleanType(); - case VM_DATA_TYPE_CHAR: return getCharType(); - default: assert(0); - } - return NULL; - } - -private: - void* systemObjectVMTypeHandle; - void* systemClassVMTypeHandle; - void* systemStringVMTypeHandle; -}; - -class DrlVMMethodSignatureDesc : public MethodSignatureDesc { -public: - DrlVMMethodSignatureDesc(Method_Signature_Handle ms,DrlVMCompilationInterface* ci) - : drlSigHandle(ms), compilationInterface(ci), paramTypes(NULL) {} - uint32 getNumParams(); - Type* getParamType(uint32 paramIndex); - Type** getParamTypes(); - Type* getReturnType(); -private: - Method_Signature_Handle drlSigHandle; - DrlVMCompilationInterface* compilationInterface; - Type** paramTypes; -}; - -//////////////////////////////////////////// -///////// DrlVMFieldDesc////////////////////// -//////////////////////////////////////////// - -class DrlVMFieldDesc : public FieldDesc { -public: - DrlVMFieldDesc(Field_Handle field, - DrlVMCompilationInterface* ci, - uint32 i) - : drlField(field), compilationInterface(ci), id(i) {} - - uint32 getId() {return id;} - const char* getName() {return field_get_name(drlField);} - const char* getSignatureString() { return field_get_descriptor(drlField); } - void printFullName(::std::ostream &os) { os<getName()<<"::"<getName()<<"::"<") == 0; } - bool isInstanceInitializer() {return strcmp(getName(), "") == 0; } - bool isMethodClassIsLikelyExceptionType(); - // - // Method info - // - - bool isJavaByteCodes() {return true;} - const Byte* getByteCodes() {return method_get_byte_code_addr(drlMethod);} - uint32 getByteCodeSize() {return (uint32) method_get_byte_code_size(drlMethod);} - uint16 getMaxStack() {return (uint16) method_get_max_stack(drlMethod);} - uint32 getNumHandlers() {return method_get_num_handlers(drlMethod);} - uint32 getNumThrows() {return method_number_throws(drlMethod);} - NamedType* getThrowType(uint32 i); - bool hasAnnotation(NamedType* type); - - // - // accessors for method info, code and data - // - virtual Byte* getInfoBlock(); - virtual uint32 getInfoBlockSize(); - virtual Byte* getCodeBlockAddress(int32 id); - virtual uint32 getCodeBlockSize(int32 id); - virtual POINTER_SIZE_INT getUniqueId(); - - // - // DRL kernel - // - bool isOverridden() {return method_is_overridden(drlMethod)?true:false;} - uint32 getOffset() {return method_get_offset(drlMethod);} - void* getIndirectAddress(){return method_get_indirect_address(drlMethod);} - bool isAddressFinal(); - // - // Signature and handler parsing - // - unsigned parseJavaHandlers(ExceptionCallback&); - void parseCliHandlers(ExceptionCallback&); - - uint32 getNumVars() {return method_vars_get_number(drlMethod);} - bool isVarPinned(uint32 varIndex); - Type* getVarType(uint32 varIndex); - - MethodSignatureDesc* getMethodSig() {return &methodSig;} - - // - // DRL specific methods - // - Method_Handle getDrlVMMethod() const {return drlMethod;} - JIT_Handle getJitHandle() const {return jitHandle;} - // - // handleMap method are used to register/unregister main map for all Container handlers - virtual void* getHandleMap() {return handleMap;} - virtual void setHandleMap(void* hndMap) {handleMap = hndMap;} - -private: - Method_Handle drlMethod; - uint32 id; - DrlVMCompilationInterface* compilationInterface; - DrlVMMethodSignatureDesc methodSig; - void* handleMap; - JIT_Handle jitHandle; -}; - - -class DrlVMDataInterface : public DataInterface { -public: - DrlVMDataInterface() {} - virtual bool areReferencesCompressed(); - virtual void* getHeapBase(); - virtual void* getHeapCeiling(); -}; - - -class DrlVMClassHierarchyIterator : public ClassHierarchyIterator { -public: - DrlVMClassHierarchyIterator(TypeManager& typeManager, ObjectType* objType) - : typeManager(typeManager) { - valid = (class_iterator_initialize(&iterator, (Class_Handle) objType->getVMTypeHandle()) != 0); - } - bool isValid() { return valid; } - bool hasNext() { Class_Handle handle = class_iterator_get_current(&iterator); return handle != NULL; } - ObjectType* getNext() { ObjectType* type = typeManager.getObjectType(class_iterator_get_current(&iterator)); class_iterator_advance(&iterator); return type; } - -private: - TypeManager& typeManager; - bool valid; - ChaClassIterator iterator; -}; - -class DrlVMClassHierarchyMethodIterator : public ClassHierarchyMethodIterator { -public: - DrlVMClassHierarchyMethodIterator(DrlVMCompilationInterface& compilationInterface, ObjectType* objType, MethodDesc* methodDesc) - : compilationInterface(compilationInterface) { - valid = (method_iterator_initialize(&iterator, ((DrlVMMethodDesc*) methodDesc)->getDrlVMMethod(), (Class_Handle) objType->getVMTypeHandle()) != 0); - } - bool isValid() { return valid; } - bool hasNext() { Method_Handle handle = method_iterator_get_current(&iterator); return handle != NULL; } - MethodDesc* getNext(); - -private: - DrlVMCompilationInterface& compilationInterface; - bool valid; - ChaMethodIterator iterator; -}; - -///////////////////////////////// -// DRL Compilation Interface // -///////////////////////////////// - -class DrlVMCompilationInterface : public CompilationInterface { -public: - DrlVMCompilationInterface(Compile_Handle c, - Method_Handle m, - JIT_Handle jit, - MemoryManager& mm, - OpenMethodExecutionParams& comp_params, - CompilationContext* cc) - : CompilationInterface(cc), memManager(mm), fieldDescs(mm,32), methodDescs(mm,32), - dataInterface(), typeManager(mm), compilation_params(comp_params) - { - compileHandle = c; - nextMemberId = 0; - typeManager.init(*this); - methodToCompile = NULL; - methodToCompile = getMethodDesc(m, jit); - flushToZeroAllowed = !methodToCompile->isJavaByteCodes(); - } - - void setCompilationContext(CompilationContext* cc) { - compilationContext = cc; - } - - // returns the method to compile - MethodDesc* getMethodToCompile() {return methodToCompile;} - - void* getRuntimeHelperAddress(RuntimeHelperId); - void* getRuntimeHelperAddressForType(RuntimeHelperId, Type*); - - // sets and gets MethodSideEffect property for the compiled method - CompilationInterface::MethodSideEffect getMethodHasSideEffect(MethodDesc *m); - void setMethodHasSideEffect(MethodDesc *m, CompilationInterface::MethodSideEffect mse); - - // - // Exception registration API. - // All functions a for the method being compiled - // - void setNumExceptionHandler(uint32 numHandlers); - void setExceptionHandlerInfo(uint32 exceptionHandlerNumber, - Byte* startAddr, - Byte* endAddr, - Byte* handlerAddr, - NamedType* exceptionType, - bool exceptionObjIsDead); - bool areReferencesCompressed() { - return dataInterface.areReferencesCompressed(); - } - void* getHeapBase() { - return dataInterface.getHeapBase(); - } - uint32 getVTableOffset() { - return object_get_vtable_offset(); - } - bool areVTablePtrsCompressed() { - return (vm_vtable_pointers_are_compressed() != 0); - } - uint32 getVTablePtrSize() { - return vm_get_vtable_ptr_size(); - } - uint64 getVTableBase() { - return vm_get_vtable_base(); - } - - // to get the owner of a method - Class_Handle methodGetClass(MethodDesc* method); - // token resolution methods - MethodSignatureDesc* resolveSignature(MethodDesc* enclosingMethodDesc, - uint32 sigToken); - FieldDesc* resolveField(MethodDesc* enclosingMethod, - uint32 fieldToken, - bool putfield); - FieldDesc* resolveFieldByIndex(NamedType *klass, int index, NamedType **fieldType); - FieldDesc* resolveStaticField(MethodDesc* enclosingMethod, - uint32 fieldToken, - bool putfield); - MethodDesc* resolveVirtualMethod(MethodDesc* enclosingMethod, - uint32 methodToken); - MethodDesc* resolveSpecialMethod(MethodDesc* enclosingMethod, - uint32 methodToken); - MethodDesc* resolveMethod(MethodDesc* enclosingMethod, - uint32 methodToken); - MethodDesc* resolveStaticMethod(MethodDesc* enclosingMethod, - uint32 methodToken); - MethodDesc* resolveInterfaceMethod(MethodDesc* enclosingMethod, - uint32 methodToken); - NamedType* resolveNamedType(MethodDesc* enclosingMethod, - uint32 typeToken); - NamedType* resolveNamedTypeNew(MethodDesc* enclosingMethod, - uint32 typeToken); - Type* getFieldType(MethodDesc* enclosingMethodDesc, uint32 entryCPIndex); - const char* methodSignatureString(MethodDesc* enclosingMethodDesc, uint32 methodToken); - - // resolve-by-name methods - virtual ObjectType * resolveClassUsingBootstrapClassloader( const char * klassName ); - virtual MethodDesc * resolveMethod( ObjectType * klass, const char * methodName, const char * methodSig); - - void* loadStringObject(MethodDesc* enclosingMethod, - uint32 stringToken); - void* loadToken(MethodDesc* enclosingMethod,uint32 token); - Type* getConstantType(MethodDesc* enclosingMethod, - uint32 constantToken); - const void* getConstantValue(MethodDesc* enclosingMethod, - uint32 constantToken); - MethodDesc* getOverriddenMethod(NamedType *type, MethodDesc * methodDesc); - - ClassHierarchyIterator* getClassHierarchyIterator(ObjectType* baseType); - - ClassHierarchyMethodIterator* getClassHierarchyMethodIterator(ObjectType* baseType, MethodDesc* methodDesc); - - void hardAssert(const char *message, int line, const char *file); - - // accessors for method info, code and data - Byte* getInfoBlock(MethodDesc*); - uint32 getInfoBlockSize(MethodDesc*); - Byte* getCodeBlockAddress(MethodDesc*, int32 id); - uint32 getCodeBlockSize(MethodDesc*, int32 id); - - // Memory allocation API - // all of these are for the method being compiled - Byte* allocateCodeBlock(size_t size, size_t alignment, CodeBlockHeat heat, int32 id, - bool simulate) { - uint32 drlHeat; - if (heat == CodeBlockHeatMin) - drlHeat = CODE_BLOCK_HEAT_COLD; - else if (heat == CodeBlockHeatMax) - drlHeat = CODE_BLOCK_HEAT_MAX/2; - else { - assert (heat == CodeBlockHeatDefault); - drlHeat = CODE_BLOCK_HEAT_DEFAULT; - } - return method_allocate_code_block(methodToCompile->getDrlVMMethod(), getJitHandle(), - size, alignment, drlHeat, id, simulate ? CAA_Simulate : CAA_Allocate); - } - Byte* allocateDataBlock(size_t size, size_t alignment) { - return method_allocate_data_block(methodToCompile->getDrlVMMethod(),getJitHandle(),size, alignment); - } - Byte* allocateInfoBlock(size_t size) { - size += sizeof(void *); - Byte *addr = method_allocate_info_block(methodToCompile->getDrlVMMethod(),getJitHandle(),size); - return (addr + sizeof(void *)); - } - Byte* allocateJITDataBlock(size_t size, size_t alignment) { - return method_allocate_jit_data_block(methodToCompile->getDrlVMMethod(),getJitHandle(),size, alignment); - } - // allocate memory block with no purpose specified - Byte* allocateMemoryBlock(size_t size) { - return (Byte *)malloc(size); - } - - void lockMethodData(void) { g_compileLock.lock(); } - void unlockMethodData(void) { g_compileLock.unlock(); } - - // methods that register JIT to be notified of various events - void setNotifyWhenClassIsExtended(ObjectType * type, void * callbackData); - void setNotifyWhenMethodIsOverridden(MethodDesc * methodDesc, void * callbackData); - void setNotifyWhenMethodIsRecompiled(MethodDesc * methodDesc, void * callbackData); - - - - // write barriers stuff - bool insertWriteBarriers() { - return compilation_params.exe_insert_write_barriers; - } - - bool isBCMapInfoRequired() { - bool res = compilation_params.exe_do_code_mapping; - // exe_do_code_mapping should be used for different ti related byte code - // mapping calculations - // full byte code mapping could be enabled by IRBuilder flag now - // this method used to access to byte code low level maps and - // enables byte codes for stack traces only -// res = true; - return res; - } - void setBCMapInfoRequired(bool is_supported) { - compilation_params.exe_do_code_mapping = is_supported; - } - - bool isCompileLoadEventRequired() { - return compilation_params.exe_notify_compiled_method_load; - } - - virtual void sendCompiledMethodLoadEvent(MethodDesc* methodDesc, MethodDesc* outerDesc, - uint32 codeSize, void* codeAddr, uint32 mapLength, - AddrLocation* addrLocationMap, void* compileInfo); - - virtual OpenMethodExecutionParams& getCompilationParams() { - return compilation_params; - } - - // should flush to zero be allowed for floating-point operations ? - bool isFlushToZeroAllowed() { - return flushToZeroAllowed; - } - // - // Returns true if jit may inline VM functionality for monitorenter and monitorexit - // If true is returned 'syncInfo' is filled in with the synchronization parameters. - // - bool mayInlineObjectSynchronization(ObjectSynchronizationInfo & syncInfo); - - // - // Returns the calling convention for managed code. - // - VmCallingConvention getManagedCallingConvention() { - switch (vm_managed_calling_convention()) { - case CC_Vm: - return CallingConvention_Drl; - default: - assert(0); - return (VmCallingConvention) -1; - }; - } - VmCallingConvention getRuntimeHelperCallingConvention(RuntimeHelperId id); - - bool compileMethod(MethodDesc *method); - - void* getRuntimeMethodHandle(MethodDesc *method) { - return ((DrlVMMethodDesc*)method)->getDrlVMMethod(); - } - - // - // for internal use - // - TypeManager& getTypeManager() {return typeManager;} - MemoryManager& getMemManager() {return memManager;} - Type* getTypeFromDrlVMTypeHandle(Type_Info_Handle, - bool isManagedPointer); - DrlVMFieldDesc* getFieldDesc(Field_Handle field) { - DrlVMFieldDesc* fieldDesc = fieldDescs.lookup(field); - if (fieldDesc == NULL) { - fieldDesc = new (memManager) - DrlVMFieldDesc(field,this,nextMemberId++); - fieldDescs.insert(field,fieldDesc); - } - return fieldDesc; - } - DrlVMMethodDesc* getMethodDesc(Method_Handle method) { - return getMethodDesc(method, getJitHandle()); - } - - DrlVMMethodDesc* getMethodDesc(Method_Handle method, JIT_Handle jit) { - assert(method); - DrlVMMethodDesc* methodDesc = methodDescs.lookup(method); - if (methodDesc == NULL) { - methodDesc = new (memManager) - DrlVMMethodDesc(method,this,nextMemberId++, jit); - methodDescs.insert(method,methodDesc); - } - return methodDesc; - } - -private: - Type* getTypeFromDrlVMTypeHandle(Type_Info_Handle); - VM_RT_SUPPORT translateHelperId(RuntimeHelperId runtimeHelperId); - JIT_Handle getJitHandle() const; - - MemoryManager& memManager; - PtrHashTable fieldDescs; - PtrHashTable methodDescs; - DrlVMDataInterface dataInterface; - DrlVMTypeManager typeManager; - DrlVMMethodDesc* methodToCompile; - Compile_Handle compileHandle; - bool flushToZeroAllowed; - uint32 nextMemberId; - OpenMethodExecutionParams& compilation_params; -}; - -class DrlVMGCInterface : public GCInterface { -public: - DrlVMGCInterface(GC_Enumeration_Handle gcHandle) : gcHandle(gcHandle) {} - - virtual void enumerateRootReference(void** reference) { - vm_enumerate_root_reference(reference, FALSE); - } - - virtual void enumerateCompressedRootReference(uint32* reference) { - vm_enumerate_compressed_root_reference(reference, FALSE); - } - - virtual void enumerateRootManagedReference(void** slotReference, int slotOffset) { - vm_enumerate_root_interior_pointer(slotReference, slotOffset, FALSE); - } - -private: - GC_Enumeration_Handle gcHandle; -}; - - -class DrlVMThreadDumpEnumerator : public GCInterface { -public: - DrlVMThreadDumpEnumerator() {} - - virtual void enumerateRootReference(void** reference) { - vm_check_if_monitor(reference, 0, 0, 0, FALSE, 1); - } - - virtual void enumerateCompressedRootReference(uint32* reference) { - vm_check_if_monitor(0, 0, reference, 0, FALSE, 2); - } - - virtual void enumerateRootManagedReference(void** slotReference, int slotOffset) { - vm_check_if_monitor(slotReference, 0, 0, slotOffset, FALSE, 3); - } -}; - -class DrlVMBinaryRewritingInterface : public BinaryRewritingInterface { -public: - DrlVMBinaryRewritingInterface() {} - virtual void rewriteCodeBlock(Byte* codeBlock, Byte* newCode, size_t size); -}; - -} //namespace Jitrino - -#endif // _DRLVMINTERFACEIMPL_H_ Index: vm/jitrino/src/vm/VMInterface.cpp =================================================================== --- vm/jitrino/src/vm/VMInterface.cpp (revision 523181) +++ vm/jitrino/src/vm/VMInterface.cpp (working copy) @@ -15,22 +15,12 @@ * limitations under the License. */ -/** - * @author Intel, Mikhail Y. Fursov - * @version $Revision: 1.15.12.2.4.4 $ - * - */ - #include #include "VMInterface.h" +#include "PlatformDependant.h" namespace Jitrino { -// -// This file contains definitions of the interface properties that -// do not depend on the interface implementation. -// - /* The following struct and array contains a mapping between RuntimeHelperId and its string representation. Index: vm/jitrino/src/vm/EMInterface.h =================================================================== --- vm/jitrino/src/vm/EMInterface.h (revision 523181) +++ vm/jitrino/src/vm/EMInterface.h (working copy) @@ -14,16 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* COPYRIGHT_NOTICE */ -/** -* @author Mikhail Y. Fursov -* @version $Revision$ -*/ - #ifndef _EMINTERFACE_H_ #define _EMINTERFACE_H_ +#include "open/em_profile_access.h" #include "VMInterface.h" namespace Jitrino { @@ -40,103 +35,127 @@ JITProfilingRole_USE = 2 }; -//M1 implementation of profiling interfaces -class MethodProfile; -class MemoryManager; -class EntryBackedgeMethodProfile; -class EdgeMethodProfile; -class ValueMethodProfile; +class MethodProfile { +public: + MethodProfile(Method_Profile_Handle _handle, ProfileType _type, MethodDesc& _md) + : handle(_handle), type(_type), md(_md){} + virtual ~MethodProfile(){}; + Method_Profile_Handle getHandle() const { return handle;} + MethodDesc& getMethod() const {return md;} + ProfileType getProfileType() const {return type;} +private: + Method_Profile_Handle handle; + ProfileType type; + MethodDesc& md; +}; -typedef void PC_Callback_Fn(Method_Profile_Handle); +class EntryBackedgeMethodProfile : public MethodProfile { +public: + EntryBackedgeMethodProfile(Method_Profile_Handle mph, MethodDesc& md, uint32* _entryCounter, uint32 *_backedgeCounter) + : MethodProfile(mph, ProfileType_EntryBackedge, md), entryCounter(_entryCounter), backedgeCounter(_backedgeCounter){} + uint32 getEntryExecCount() const {return *entryCounter;} + uint32 getBackedgeExecCount() const {return *backedgeCounter;} + uint32* getEntryCounter() const {return entryCounter;} + uint32* getBackedgeCounter() const {return backedgeCounter;} + +private: + uint32* entryCounter; + uint32* backedgeCounter; +}; + +class EdgeMethodProfile : public MethodProfile { +public: + EdgeMethodProfile (Method_Profile_Handle handle, MethodDesc& md, EM_ProfileAccessInterface* _profileAccessInterface) + : MethodProfile(handle, ProfileType_Edge, md), profileAccessInterface(_profileAccessInterface){} + + uint32 getNumCounters() const; + uint32 getCheckSum() const; + uint32* getEntryCounter() const; + uint32* getCounter(uint32 key) const; + +private: + EM_ProfileAccessInterface* profileAccessInterface; +}; + +class ValueMethodProfile: public MethodProfile { +public: + ValueMethodProfile (Method_Profile_Handle handle, MethodDesc& md, EM_ProfileAccessInterface* _profileAccessInterface) + : MethodProfile(handle, ProfileType_Value, md), profileAccessInterface(_profileAccessInterface){} + + POINTER_SIZE_INT getTopValue(uint32 instructionKey) const; + void dumpValues(std::ostream& os) const; + +private: + EM_ProfileAccessInterface* profileAccessInterface; +}; + + class ProfilingInterface { public: - virtual ~ProfilingInterface(){}; - virtual MethodProfile* getMethodProfile(MemoryManager& mm, ProfileType type, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const = 0; + PC_Handle getPCHandle(ProfileType type) const; + EM_ProfileAccessInterface* getEMProfileAccessInterface() const { return profileAccessInterface; } + + MethodProfile* getMethodProfile(MemoryManager& mm, ProfileType type, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const; // Returns EM method profile handle. This method is needed when we need to update method profile // at run-time i.e. when there is no any memory managers available. - virtual Method_Profile_Handle getMethodProfileHandle(ProfileType type, MethodDesc& md) const = 0; - virtual EM_ProfileAccessInterface* getEMProfileAccessInterface() const = 0; + Method_Profile_Handle getMethodProfileHandle(ProfileType type, MethodDesc& md) const; - virtual bool hasMethodProfile(ProfileType type, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const = 0; - virtual bool enableProfiling(PC_Handle pc, JITProfilingRole role) = 0; - virtual bool isProfilingEnabled(ProfileType pcType, JITProfilingRole jitRole) const = 0; + bool hasMethodProfile(ProfileType type, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const; + bool enableProfiling(PC_Handle pc, JITProfilingRole role); + bool isProfilingEnabled(ProfileType pcType, JITProfilingRole jitRole) const; - virtual uint32 getProfileMethodCount(MethodDesc& md, JITProfilingRole role = JITProfilingRole_USE) const = 0; + uint32 getProfileMethodCount(MethodDesc& md, JITProfilingRole role = JITProfilingRole_USE) const; - virtual EntryBackedgeMethodProfile* createEBMethodProfile(MemoryManager& mm, MethodDesc& md) =0; - virtual bool isEBProfilerInSyncMode() const = 0; - virtual PC_Callback_Fn* getEBProfilerSyncModeCallback() const = 0; + EntryBackedgeMethodProfile* createEBMethodProfile(MemoryManager& mm, MethodDesc& md); + bool isEBProfilerInSyncMode() const; + typedef void PC_Callback_Fn(Method_Profile_Handle); + PC_Callback_Fn* getEBProfilerSyncModeCallback() const; - virtual EdgeMethodProfile* createEdgeMethodProfile(MemoryManager& mm, MethodDesc& md, uint32 numEdgeCounters, uint32* counterKeys, uint32 checkSum) =0; + EdgeMethodProfile* createEdgeMethodProfile(MemoryManager& mm, MethodDesc& md, uint32 numEdgeCounters, uint32* counterKeys, uint32 checkSum); - virtual uint32 getMethodEntryThreshold() const = 0; - virtual uint32 getBackedgeThreshold() const = 0; - virtual EntryBackedgeMethodProfile* getEBMethodProfile(MemoryManager& mm, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const { + uint32 getMethodEntryThreshold() const; + uint32 getBackedgeThreshold() const; + + EntryBackedgeMethodProfile* getEBMethodProfile(MemoryManager& mm, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const { return (EntryBackedgeMethodProfile*)getMethodProfile(mm, ProfileType_EntryBackedge, md, role); } - virtual EdgeMethodProfile* getEdgeMethodProfile(MemoryManager& mm, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const { + EdgeMethodProfile* getEdgeMethodProfile(MemoryManager& mm, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const { return (EdgeMethodProfile*)getMethodProfile(mm, ProfileType_Edge, md, role); } // value profiler - virtual ValueMethodProfile* createValueMethodProfile (MemoryManager& mm, MethodDesc& md, uint32 numKeys, uint32* Keys) = 0; + ValueMethodProfile* createValueMethodProfile (MemoryManager& mm, MethodDesc& md, uint32 numKeys, uint32* Keys); - virtual ValueMethodProfile* getValueMethodProfile(MemoryManager& mm, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const { + ValueMethodProfile* getValueMethodProfile(MemoryManager& mm, MethodDesc& md, JITProfilingRole role=JITProfilingRole_USE) const { return (ValueMethodProfile*)getMethodProfile(mm, ProfileType_Value, md, role); } -}; -class MethodProfile { -public: - MethodProfile(Method_Profile_Handle _handle, ProfileType _type, MethodDesc& _md) - : handle(_handle), type(_type), md(_md){} - virtual ~MethodProfile(){}; - Method_Profile_Handle getHandle() const { return handle;} - MethodDesc& getMethod() const {return md;} - ProfileType getProfileType() const {return type;} + ProfilingInterface(EM_Handle _em, JIT_Handle _jit, EM_ProfileAccessInterface* emProfileAccess) + : emHandle(_em), ebPCHandle(NULL), edgePCHandle(NULL), valuePCHandle(NULL), jitHandle(_jit), profileAccessInterface(emProfileAccess), + jitRole(JITProfilingRole_USE), profilingEnabled(false){} + private: - Method_Profile_Handle handle; - ProfileType type; - MethodDesc& md; + EM_Handle emHandle; + // Various types of the profile collectors + PC_Handle ebPCHandle, edgePCHandle, valuePCHandle; + // ProfileType pcType; + JIT_Handle jitHandle; + EM_ProfileAccessInterface* profileAccessInterface; + // Only one role supported at one time + JITProfilingRole jitRole; + // There is only one flag so edge and value profile may work only simultaneously + // TODO: Better solution is needed when we want to have independent profiles + bool profilingEnabled; }; -class EntryBackedgeMethodProfile : public MethodProfile { -public: - EntryBackedgeMethodProfile (Method_Profile_Handle handle, MethodDesc& md): MethodProfile(handle, ProfileType_EntryBackedge, md){} - - virtual uint32 getEntryExecCount() const = 0; - virtual uint32 getBackedgeExecCount() const = 0; - virtual uint32* getEntryCounter() const = 0; - virtual uint32* getBackedgeCounter() const = 0; -}; - -class EdgeMethodProfile : public MethodProfile { -public: - EdgeMethodProfile (Method_Profile_Handle handle, MethodDesc& md): MethodProfile(handle, ProfileType_Edge, md){} - - virtual uint32 getNumCounters() const = 0; - virtual uint32 getCheckSum() const = 0; - virtual uint32* getEntryCounter() const = 0; - virtual uint32* getCounter(uint32 key) const = 0; -}; - -class ValueMethodProfile: public MethodProfile { -public: - ValueMethodProfile (Method_Profile_Handle handle, MethodDesc& md) : MethodProfile(handle, ProfileType_Value, md){} - - virtual POINTER_SIZE_INT getTopValue(uint32 instructionKey) const = 0; - virtual void dumpValues(std::ostream& os) const = 0; -}; - - };//namespace #endif //_EMINTERFACE_H_ Index: vm/jitrino/src/vm/VMInterface.h =================================================================== --- vm/jitrino/src/vm/VMInterface.h (revision 523181) +++ vm/jitrino/src/vm/VMInterface.h (working copy) @@ -1,319 +1,291 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ -/** - * @author Intel, Mikhail Y. Fursov - * @version $Revision: 1.38.8.4.4.4 $ - */ - #ifndef _VMINTERFACE_H_ #define _VMINTERFACE_H_ -#include -#include -#ifdef __GNUC__ -typedef ::std::size_t size_t; -#endif - +#include +#include "open/em.h" #include "open/types.h" -#include "jit_export.h" +#include "jit_runtime_support.h" #include "jit_intf.h" -#include -#include -#include "PlatformDependant.h" -#define LOG_DOMAIN "jitrino" - namespace Jitrino { -// external declarations +// external and forward declarations class TypeManager; -class JITInstanceContext; class Type; class NamedType; class ObjectType; class MethodPtrType; -class PersistentInstructionId; class MemoryManager; class CompilationContext; +class CompilationInterface; +template class PtrHashTable; + +class VMInterface { +public: + // + // VM specific methods for types + // + static void* getSystemObjectVMTypeHandle(); + static void* getSystemClassVMTypeHandle(); + static void* getSystemStringVMTypeHandle(); + static void* getArrayVMTypeHandle(void* elemVMTypeHandle,bool isUnboxed); + static const char* getTypeName(void* vmTypeHandle); + static const char* getTypeNameQualifier(void* vmTypeHandle); + static void* getSuperTypeVMTypeHandle(void* vmTypeHandle); + static void* getArrayElemVMTypeHandle(void* vmTypeHandle); + static bool isArrayType(void* vmTypeHandle); + static bool isArrayOfPrimitiveElements(void* vmTypeHandle); + static bool isEnumType(void* vmTypeHandle); + static bool isValueType(void* vmTypeHandle); + static bool isFinalType(void* vmTypeHandle); + static bool isLikelyExceptionType(void* vmTypeHandle); + static bool isInterfaceType(void* vmTypeHandle); + static bool isAbstractType(void* vmTypeHandle); + static bool needsInitialization(void* vmTypeHandle); + static bool isFinalizable(void* vmTypeHandle); + static bool isBeforeFieldInit(void* vmTypeHandle); + static bool getClassFastInstanceOfFlag(void* vmTypeHandle); + static int getClassDepth(void* vmTypeHandle); + static bool isInitialized(void* vmTypeHandle); + static void* getVTable(void* vmTypeHandle); + static void* getRuntimeClassHandle(void* vmTypeHandle); + static void* getAllocationHandle(void* vmTypeHandle); + static bool isSubClassOf(void* vmTypeHandle1,void* vmTypeHandle2); + static uint32 getArrayElemOffset(void* vmElemTypeHandle,bool isUnboxed); + static uint32 getObjectSize(void * vmTypeHandle); + static uint32 getArrayLengthOffset(); + + static void* getTypeHandleFromAllocationHandle(void* vmAllocationHandle); + static void* getTypeHandleFromVTable(void* vtHandle); + + static uint32 flagTLSSuspendRequestOffset(); + static uint32 flagTLSThreadStateOffset(); + + + // returns true if vtable pointers are compressed + //static bool areVTablePtrsCompressed() {return vm_vtable_pointers_are_compressed();} + + // returns size of vtable pointer (currently 4 if compressed and 8 otherwise) + //static uint32 getVTablePtrSize() {return vm_get_vtable_ptr_size();} + + // returns the offset of an object's virtual table + static uint32 getVTableOffset(); + // returns the base for all vtables (addend to compressed vtable pointer) + static uint64 getVTableBase() {return vm_get_vtable_base();} + + // returns true if instance fields that are references are compressed + static bool areReferencesCompressed() {return vm_references_are_compressed();} + + // + // returns the base for the heap (addend to compressed heap references) + // + static void* getHeapBase(); + static void* getHeapCeiling(); + + + static void rewriteCodeBlock(Byte* codeBlock, Byte* newCode, size_t size); +}; + + /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// // O P A Q U E D E S C' S I M P L E M E N T E D B Y V M // /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// -class ExceptionCallback { +class TypeMemberDesc { public: - virtual ~ExceptionCallback() {} + TypeMemberDesc(uint32 id, CompilationInterface* ci) + : id(id), compilationInterface(ci) {} + virtual ~TypeMemberDesc() {} - virtual bool catchBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength, - uint32 exceptionTypeToken) = 0; - virtual void finallyBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength) = 0; - virtual void filterBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength, - uint32 expressionStart) = 0; - virtual void faultBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength) = 0; -}; + uint32 getId() const { return id; } + NamedType* getParentType(); + bool isParentClassIsLikelyExceptionType() const; -// -// calli standalone sig, fptr callback of type sig, and methodDesc.parseMethodSig -// -class MethodSignatureDesc { -public: - virtual ~MethodSignatureDesc() {} - virtual uint32 getNumParams() = 0; - virtual Type** getParamTypes() = 0; - virtual Type* getParamType(uint32 paramIndex) = 0; - virtual Type* getReturnType() = 0; -}; + virtual const char* getName() const = 0; + virtual const char* getSignatureString() const = 0; + virtual void printFullName(::std::ostream& os) = 0; + virtual Class_Handle getParentHandle() const = 0; -class TypeMemberDesc { -public: - virtual ~TypeMemberDesc() {} + virtual bool isPrivate() const = 0; + virtual bool isStatic() const = 0; - virtual const char* getName() = 0; - virtual const char* getSignatureString() = 0; - virtual void printFullName(::std::ostream& os) = 0; - virtual NamedType* getParentType() = 0; - virtual uint32 getId() = 0; - virtual bool isPrivate() = 0; - virtual bool isStatic() = 0; +protected: + uint32 id; + CompilationInterface* compilationInterface; + }; class FieldDesc : public TypeMemberDesc { public: - virtual ~FieldDesc() {} + FieldDesc(Field_Handle field, CompilationInterface* ci, uint32 id) + : TypeMemberDesc(id, ci), drlField(field) {} - // - // this field is constant after it is initialized - // can only be mutated by constructor (instance fields) or - // type initializer (static fields) - // - virtual bool isInitOnly() = 0; - // accesses to field cannot be reordered or CSEed - virtual bool isVolatile() = 0; - // - // this is a compile-time constant field -- static fields only - // - virtual bool isLiteral() = 0; - virtual bool isUnmanagedStatic() = 0; - virtual Type* getFieldType() = 0; - virtual uint32 getOffset() = 0; // for non-static fields - virtual void* getAddress() = 0; // for static fields + const char* getName() const {return field_get_name(drlField);} + const char* getSignatureString() const {return field_get_descriptor(drlField); } + void printFullName(::std::ostream &os); + Class_Handle getParentHandle() const; + bool isPrivate() const {return field_is_private(drlField)?true:false;} + bool isStatic() const {return field_is_static(drlField)?true:false;} + // + // this field is constant after it is initialized + // can only be mutated by constructor (instance fields) or + // type initializer (static fields) + // + bool isInitOnly() const {return field_is_final(drlField)?true:false;} + // accesses to field cannot be reordered or CSEed + bool isVolatile() const {return field_is_volatile(drlField)?true:false;} + // + // this is a compile-time constant field -- static fields only + // + bool isLiteral() const; + Type* getFieldType(); + uint32 getOffset() const; // for non-static fields + void* getAddress() const {return field_get_address(drlField);} // for static fields + Field_Handle getFieldHandle() const {return drlField; } + +private: + Field_Handle drlField; }; class MethodDesc : public TypeMemberDesc { public: - virtual ~MethodDesc() {} + MethodDesc(Method_Handle m, JIT_Handle jit, CompilationInterface* ci = NULL, uint32 id = 0) + : TypeMemberDesc(id, ci), drlMethod(m), + methodSig(method_get_signature(m)), + handleMap(NULL), + jitHandle(jit){} - virtual bool isNative() = 0; - virtual bool isSynchronized() = 0; - virtual bool isNoInlining() = 0; - virtual bool isStatic() = 0; - virtual bool isInstance() = 0; // In Java, all instance methods are virtual. In CLI, not so. - virtual bool isFinal() = 0; - virtual bool isVirtual() = 0; - virtual bool isAbstract() = 0; // isAbstract is probably not needed - virtual bool isClassInitializer() = 0; - virtual bool isInstanceInitializer() = 0; - virtual bool isMethodClassIsLikelyExceptionType() = 0; + const char* getName() const {return method_get_name(drlMethod);} + const char* getSignatureString() const {return method_get_descriptor(drlMethod); } + void printFullName(::std::ostream& os); + Class_Handle getParentHandle() const; - virtual bool isStrict() = 0; // floating-point strict - virtual bool isRequireSecObject() = 0; - virtual bool isInitLocals() = 0; // call default constructor on local vars - virtual bool isOverridden() = 0; + bool isPrivate() const {return method_is_private(drlMethod)?true:false;} + bool isStatic() const {return method_is_static(drlMethod)?true:false;} + bool isInstance() const {return method_is_static(drlMethod)?false:true;} + bool isNative() const {return method_is_native(drlMethod)?true:false;} + bool isSynchronized() const {return method_is_synchronized(drlMethod)?true:false;} + bool isNoInlining() const; + bool isFinal() const {return method_is_final(drlMethod)?true:false;} + bool isVirtual() const {return isInstance() && !isPrivate();} + bool isAbstract() const {return method_is_abstract(drlMethod)?true:false;} + // FP strict + bool isStrict() const {return method_is_strict(drlMethod)?true:false;} + bool isRequireSecObject(); //FIXME drop??? + bool isClassInitializer() const {return strcmp(getName(), "") == 0; } + bool isInstanceInitializer() const {return strcmp(getName(), "") == 0; } - virtual bool isJavaByteCodes() = 0; // are bytecodes Java or CLI? - virtual const Byte* getByteCodes() = 0; - virtual uint32 getByteCodeSize() = 0; - virtual uint16 getMaxStack() = 0; - virtual uint32 getOffset() = 0; - virtual bool isAddressFinal() = 0; - virtual void* getIndirectAddress()= 0; - virtual uint32 getNumHandlers() = 0; - virtual uint32 getNumThrows() = 0; - virtual NamedType* getThrowType(uint32 i) = 0; - virtual bool hasAnnotation(NamedType* type) = 0; - - // Exception handler and signature parsing API - virtual unsigned parseJavaHandlers(ExceptionCallback&) = 0; - virtual void parseCliHandlers(ExceptionCallback&) = 0; - virtual bool isVarPinned(uint32 varIndex) = 0; - virtual Type* getVarType(uint32 varType) = 0; - virtual uint32 getNumVars() = 0; - virtual MethodSignatureDesc* getMethodSig() = 0; + // + // Method info + // - // - // accessors for method info, code and data - // - virtual Byte* getInfoBlock() = 0; - virtual uint32 getInfoBlockSize() = 0; - virtual Byte* getCodeBlockAddress(int32 id) = 0; - virtual uint32 getCodeBlockSize(int32 id) = 0; + const Byte* getByteCodes() const {return method_get_byte_code_addr(drlMethod);} + uint32 getByteCodeSize() const {return (uint32) method_get_byte_code_size(drlMethod);} + uint16 getMaxStack() const {return (uint16) method_get_max_stack(drlMethod);} + uint32 getNumHandlers() const {return method_get_num_handlers(drlMethod);} + void getHandlerInfo(unsigned index, unsigned* beginOffset, + unsigned* endOffset, unsigned* handlerOffset, unsigned* handlerClassIndex) const; + uint32 getNumThrows() const {return method_number_throws(drlMethod);} + NamedType* getThrowType(uint32 i); + bool hasAnnotation(NamedType* type) const; + // + // accessors for method info, code and data + // + Byte* getInfoBlock() const; + uint32 getInfoBlockSize() const; + Byte* getCodeBlockAddress(int32 id) const; + uint32 getCodeBlockSize(int32 id) const; - // - // accessors for DynoptInfo of this method - // - virtual POINTER_SIZE_INT getUniqueId() = 0; - - virtual void* getHandleMap() = 0; - virtual void setHandleMap(void* ) = 0; -}; + // sets and gets MethodSideEffect property for the compiled method + Method_Side_Effects getSideEffect() const; + void setSideEffect(Method_Side_Effects mse); -// -// The Persistent Instruction Id is used to generate a profile instruction map and to -// feedback profile information into Jitrino. -// -class PersistentInstructionId { -public: - PersistentInstructionId() - : methodDesc(NULL), localInstructionId((uint32)-1) {} + // + // Exception registration API. + // + void setNumExceptionHandler(uint32 numHandlers); + void setExceptionHandlerInfo(uint32 exceptionHandlerNumber, + Byte* startAddr, + Byte* endAddr, + Byte* handlerAddr, + NamedType* exceptionType, + bool exceptionObjIsDead); - PersistentInstructionId(MethodDesc* methodDesc, uint32 localInstructionId) - : methodDesc(methodDesc), localInstructionId(localInstructionId) {} - bool isValid() const { return (methodDesc != NULL); } + // + // DRL kernel + // + bool isOverridden() const {return method_is_overridden(drlMethod)?true:false;} + uint32 getOffset() const {return method_get_offset(drlMethod);} + void* getIndirectAddress() const {return method_get_indirect_address(drlMethod);} - MethodDesc& getMethodDesc() const { return *methodDesc; } - uint32 getLocalInstructionId() const { return localInstructionId; } + uint32 getNumVars() const {return method_vars_get_number(drlMethod);} - // For IPF codegen to store block ids into pid - bool hasValidLocalInstructionId() const { return localInstructionId != (uint32)-1; } + Method_Handle getMethodHandle() const {return drlMethod;} - bool operator==(const PersistentInstructionId& pid) { return methodDesc == pid.methodDesc && localInstructionId == pid.localInstructionId; } -private: - MethodDesc* methodDesc; // The source method at point the id was generated - uint32 localInstructionId; // The persistent local instruction id -}; + // + // handleMap method are used to register/unregister main map for all Container handlers + void* getHandleMap() const {return handleMap;} + void setHandleMap(void* hndMap) {handleMap = hndMap;} -inline ::std::ostream& operator<<(::std::ostream& os, const PersistentInstructionId& pid) { - os << (pid.isValid() ? pid.getMethodDesc().getName() : "NULL") << ":" - << (unsigned int) pid.getLocalInstructionId(); - return os; -} + uint32 getNumParams() const; + Type* getParamType(uint32 paramIndex) const; + Type* getReturnType() const; -class ClassHierarchyIterator { -public: - virtual ~ClassHierarchyIterator() {} - - virtual bool isValid() = 0; // true if iterator is valid - virtual bool hasNext() = 0; // true if iterator is not done - virtual ObjectType* getNext() = 0; // return next class in iterator and advance iterator +private: + JIT_Handle getJitHandle() const {return jitHandle;} + Method_Handle drlMethod; + Method_Signature_Handle methodSig; + void* handleMap; + JIT_Handle jitHandle; }; class ClassHierarchyMethodIterator { public: - virtual ~ClassHierarchyMethodIterator() {} - virtual bool hasNext() = 0; // true if iterator is not done - virtual MethodDesc* getNext() = 0; // return next class in iterator and advance iterator + ClassHierarchyMethodIterator(CompilationInterface& compilationInterface, ObjectType* objType, MethodDesc* methodDesc); + bool isValid() const { return valid; } + bool hasNext() const; + MethodDesc* getNext(); + +private: + CompilationInterface& compilationInterface; + bool valid; + ChaMethodIterator iterator; }; class CompilationInterface { public: + CompilationInterface(Compile_Handle c, + Method_Handle m, + JIT_Handle jit, + MemoryManager& mm, + OpenMethodExecutionParams& comp_params, + CompilationContext* cc, TypeManager& tpm); - CompilationInterface(CompilationContext* cc) : compilationContext(cc){} - virtual ~CompilationInterface() {} - - virtual TypeManager& getTypeManager() = 0; // - // returns the method to compile - // - virtual MethodDesc* getMethodToCompile() = 0; - // - //returns the owner of a method - // - virtual Class_Handle methodGetClass(MethodDesc* method) = 0; - // - // resolution methods - // - virtual MethodSignatureDesc* resolveSignature(MethodDesc* enclosingMethodDesc, - uint32 sigToken) = 0; - virtual FieldDesc* resolveField(MethodDesc* enclosingMethod, - uint32 fieldToken, - bool putfield) = 0; - virtual FieldDesc* resolveFieldByIndex(NamedType* klass, int index, NamedType **fieldType) = 0; - virtual FieldDesc* resolveStaticField(MethodDesc* enclosingMethod, - uint32 fieldToken, - bool putfield) = 0; - virtual MethodDesc* resolveVirtualMethod(MethodDesc* enclosingMethod, - uint32 methodToken) = 0; - virtual MethodDesc* resolveSpecialMethod(MethodDesc* enclosingMethod, - uint32 methodToken) = 0; - virtual MethodDesc* resolveMethod(MethodDesc* enclosingMethod, - uint32 methodToken) = 0; - virtual MethodDesc* resolveStaticMethod(MethodDesc* enclosingMethod, - uint32 methodToken) = 0; - virtual MethodDesc* resolveInterfaceMethod(MethodDesc* enclosingMethod, - uint32 methodToken) = 0; - virtual NamedType* resolveNamedType(MethodDesc* enclosingMethod, - uint32 typeToken) = 0; - virtual NamedType* resolveNamedTypeNew(MethodDesc* enclosingMethod, - uint32 typeToken) = 0; - virtual Type* getFieldType(MethodDesc* enclosingMethodDesc, uint32 entryCPIndex) = 0; - virtual const char* methodSignatureString(MethodDesc* enclosingMethodDesc, uint32 methodToken) = 0; - virtual void* loadStringObject(MethodDesc* enclosingMethod, - uint32 stringToken)= 0; - virtual void* loadToken(MethodDesc* enclosingMethod,uint32 token) = 0; - virtual Type* getConstantType(MethodDesc* enclosingMethod, - uint32 constantToken) = 0; - virtual const void* getConstantValue(MethodDesc* enclosingMethod, - uint32 constantToken) = 0; - // resolve-by-name methods - /** - * Resolve a system class by its name. - * Returns NULL if no such class found. - */ - virtual ObjectType * resolveClassUsingBootstrapClassloader( const char * klassName ) = 0; - /** - * Recursively looks up for a given method with a given signature in the given class. - * Returns NULL if no such method found. - */ - virtual MethodDesc* resolveMethod(ObjectType * klass, const char * methodName, const char * methodSig) = 0; - - // Class type is a subclass of ch=mh->getParentType() The function returns - // a method description for a method overriding mh in type or in the closest - // superclass of ch that overrides mh. - virtual MethodDesc* getOverriddenMethod(NamedType *type, MethodDesc * methodDesc) = 0; - - // Return NULL if an iterator is not available for this type - virtual ClassHierarchyIterator* getClassHierarchyIterator(ObjectType* baseType) = 0; - - // Return NULL if an iterator is not available for this type and method - virtual ClassHierarchyMethodIterator* getClassHierarchyMethodIterator(ObjectType* baseType, MethodDesc* methodDesc) = 0; - - // prints message, something about line and file, and hard-exits - virtual void hardAssert(const char *message, int line, const char *file) = 0; - - // // System exceptions // enum SystemExceptionId { @@ -380,239 +352,256 @@ Helper_WriteBarrier, Num_Helpers }; - // - // Code block heat - used when a method is split into hot and cold parts - // - enum CodeBlockHeat { - CodeBlockHeatMin, - CodeBlockHeatDefault, - CodeBlockHeatMax + + enum VmCallingConvention { + CallingConvention_Drl = 0, + CallingConvention_Stdcall, + CallingConvention_Cdecl, + Num_CallingConvention }; - virtual void* getRuntimeHelperAddress(RuntimeHelperId) = 0; - virtual void* getRuntimeHelperAddressForType(RuntimeHelperId id, Type* type) = 0; + static const char* getRuntimeHelperName(RuntimeHelperId helperId); /** - * Returns RuntimeHelperId by its string representation. Name comparison - * is case-sensitive. - * If the helperName is unknown, then Helper_Null is returned. - */ + * Returns RuntimeHelperId by its string representation. Name comparison + * is case-sensitive. + * If the helperName is unknown, then Helper_Null is returned. + */ static RuntimeHelperId str2rid( const char * helperName ); - // - // method side effects (for lazy exception throwing optimization) - // - enum MethodSideEffect { - MSE_UNKNOWN, - MSE_YES, - MSE_NO, - MSE_NULL_PARAM - }; + VmCallingConvention getRuntimeHelperCallingConvention(RuntimeHelperId id); + void* getRuntimeHelperAddress(RuntimeHelperId); + void* getRuntimeHelperAddressForType(RuntimeHelperId, Type*); - virtual MethodSideEffect getMethodHasSideEffect(MethodDesc *m) = 0; - virtual void setMethodHasSideEffect(MethodDesc *m, MethodSideEffect mse) = 0; - // - // Exception registration API. - // All functions a for the method being compiled - // - virtual void setNumExceptionHandler(uint32 numHandlers) = 0; - virtual void setExceptionHandlerInfo(uint32 exceptionHandlerNumber, - Byte* startAddr, - Byte* endAddr, - Byte* handlerAddr, - NamedType* exceptionType, - bool exceptionObjIsDead) = 0; - // - // returns true if instance fields that are references are compressed - // - virtual bool areReferencesCompressed() = 0; - // - // returns the base for the heap (addend to compressed heap references) - // - virtual void* getHeapBase() = 0; - // - // returns the offset of an object's virtual table - // - virtual uint32 getVTableOffset() = 0; - // - // returns true if vtable pointers are compressed - // - virtual bool areVTablePtrsCompressed() = 0; - // - // returns size of vtable pointer (currently 4 if compressed and - // 8 otherwise) - // - virtual uint32 getVTablePtrSize() = 0; - // - // returns the base for all vtables (addend to compressed vtable pointer) - // - virtual uint64 getVTableBase() = 0; - // - // accessors for method info, code and data - // - virtual Byte* getInfoBlock(MethodDesc*) = 0; - virtual uint32 getInfoBlockSize(MethodDesc*) = 0; - virtual Byte* getCodeBlockAddress(MethodDesc*, int32 id) = 0; - virtual uint32 getCodeBlockSize(MethodDesc*, int32 id) = 0; - // + FieldDesc* resolveField(MethodDesc* enclosingMethod, + uint32 fieldToken, + bool putfield); + FieldDesc* resolveFieldByIndex(NamedType *klass, int index, NamedType **fieldType); + FieldDesc* resolveStaticField(MethodDesc* enclosingMethod, + uint32 fieldToken, + bool putfield); + MethodDesc* resolveVirtualMethod(MethodDesc* enclosingMethod, + uint32 methodToken); + MethodDesc* resolveSpecialMethod(MethodDesc* enclosingMethod, + uint32 methodToken); + //FIXME + //MethodDesc* resolveMethod(MethodDesc* enclosingMethod,uint32 methodToken){assert(false); return 0;} + MethodDesc* resolveStaticMethod(MethodDesc* enclosingMethod, + uint32 methodToken); + MethodDesc* resolveInterfaceMethod(MethodDesc* enclosingMethod, + uint32 methodToken); + NamedType* resolveNamedType(MethodDesc* enclosingMethod, + uint32 typeToken); + NamedType* resolveNamedTypeNew(MethodDesc* enclosingMethod, + uint32 typeToken); + Type* getFieldType(MethodDesc* enclosingMethodDesc, uint32 entryCPIndex); + + + // resolve-by-name methods + /** + * Resolve a system class by its name. + * Returns NULL if no such class found. + */ + ObjectType * resolveClassUsingBootstrapClassloader( const char * klassName ); + /** + * Recursively looks up for a given method with a given signature in the given class. + * Returns NULL if no such method found. + */ + MethodDesc* resolveMethod(ObjectType * klass, const char * methodName, const char * methodSig); + + // Class type is a subclass of ch=mh->getParentType() The function returns + // a method description for a method overriding mh in type or in the closest + // superclass of ch that overrides mh. + MethodDesc* getOverriddenMethod(NamedType *type, MethodDesc * methodDesc); + + ClassHierarchyMethodIterator* getClassHierarchyMethodIterator(ObjectType* baseType, MethodDesc* methodDesc); + + void* loadStringObject(MethodDesc* enclosingMethodDesc, uint32 stringToken); + Type* getConstantType(MethodDesc* enclosingMethodDesc, uint32 constantToken); + const void* getConstantValue(MethodDesc* enclosingMethodDesc, uint32 constantToken); + const char* getSignatureString(MethodDesc* enclosingMethodDesc, uint32 methodToken); + // Memory allocation API // all of these are for the method being compiled - virtual Byte* allocateCodeBlock(size_t size, size_t alignment, CodeBlockHeat, int32, bool) = 0; - virtual Byte* allocateDataBlock(size_t size, size_t alignment) = 0; - virtual Byte* allocateInfoBlock(size_t size) = 0; - virtual Byte* allocateJITDataBlock(size_t size, size_t alignment) = 0; - virtual Byte* allocateMemoryBlock(size_t) = 0; - // - // - + Byte* allocateCodeBlock(size_t size, size_t alignment, CodeBlockHeat heat, + int32 id, bool simulate); + + Byte* allocateDataBlock(size_t size, size_t alignment); + + Byte* allocateInfoBlock(size_t size); + + Byte* allocateJITDataBlock(size_t size, size_t alignment); + /** - * Acquires a lock to protect method's data modifications (i.e. code/info - * block allocations, exception handlers registration, etc) in - * multi-threaded compilation. - * The lock *must not* surround a code which may lead to execution of - * managed code, or a race and hang happen. - * For example, the managed code execution may happen during a resolution - * (invocation of resolve_XXX) to locate a class through a custom class - * loader. - * Note, that the lock is *not* per-method, and shared across all the - * methods. - */ - virtual void lockMethodData(void) = 0; - + * Acquires a lock to protect method's data modifications (i.e. code/info + * block allocations, exception handlers registration, etc) in + * multi-threaded compilation. + * The lock *must not* surround a code which may lead to execution of + * managed code, or a race and hang happen. + * For example, the managed code execution may happen during a resolution + * (invocation of resolve_XXX) to locate a class through a custom class + * loader. + * Note, that the lock is *not* per-method, and shared across all the + * methods. + */ + void lockMethodData(void); + /** - * Releases a lock which protects method's data. - */ - virtual void unlockMethodData(void) = 0; - - // + * Releases a lock which protects method's data. + */ + void unlockMethodData(void); + // methods that register JIT to be notified of various events - // - virtual void setNotifyWhenClassIsExtended(ObjectType * type, - void * callbackData) = 0; - virtual void setNotifyWhenMethodIsOverridden(MethodDesc * methodDesc, - void * callbackData) = 0; - virtual void setNotifyWhenMethodIsRecompiled(MethodDesc * methodDesc, - void * callbackData) = 0; + void setNotifyWhenClassIsExtended(ObjectType * type, void * callbackData); + void setNotifyWhenMethodIsOverridden(MethodDesc * methodDesc, void * callbackData); + void setNotifyWhenMethodIsRecompiled(MethodDesc * methodDesc, void * callbackData); - // - // write barrier instructions - virtual bool insertWriteBarriers() = 0; + bool needWriteBarriers() const { + return compilation_params.exe_insert_write_barriers; + } - // flush to zero allowed on floating-pointer operations - virtual bool isFlushToZeroAllowed() = 0; + bool isBCMapInfoRequired() const { + bool res = compilation_params.exe_do_code_mapping; + // exe_do_code_mapping should be used for different ti related byte code + // mapping calculations + // full byte code mapping could be enabled by IRBuilder flag now + // this method used to access to byte code low level maps and + // enables byte codes for stack traces only + // res = true; + return res; + } + void setBCMapInfoRequired(bool is_supported) const { + compilation_params.exe_do_code_mapping = is_supported; + } - // produce BC to native map info - virtual bool isBCMapInfoRequired() = 0; + bool isCompileLoadEventRequired() const { + return compilation_params.exe_notify_compiled_method_load; + } - virtual bool isCompileLoadEventRequired() = 0; - - // send compile - virtual void sendCompiledMethodLoadEvent(MethodDesc* methodDesc, MethodDesc* outerDesc, + void sendCompiledMethodLoadEvent(MethodDesc* methodDesc, MethodDesc* outerDesc, uint32 codeSize, void* codeAddr, uint32 mapLength, - AddrLocation* addrLocationMap, void* compileInfo) = 0; + AddrLocation* addrLocationMap, void* compileInfo); - // get compilation params - virtual OpenMethodExecutionParams& getCompilationParams() = 0; + OpenMethodExecutionParams& getCompilationParams() const { + return compilation_params; + } - // synchronization inlining - struct ObjectSynchronizationInfo { - uint32 threadIdReg; // the register number that holds id of the current thread - uint32 syncHeaderOffset; // offset in bytes of the sync header from the start of the object - uint32 syncHeaderWidth; // width in bytes of the sync header - uint32 lockOwnerOffset; // offset in bytes of the lock owner field from the start of the object - uint32 lockOwnerWidth; // width in bytes of the lock owner field in the sync header - bool jitClearsCcv; // whether the JIT needs to clear ar.ccv - }; - // - // Returns true if JIT may inline VM functionality for monitorenter and monitorexit - // If true is returned 'syncInfo' is filled in with the synchronization parameters. - // - virtual bool mayInlineObjectSynchronization(ObjectSynchronizationInfo & syncInfo) = 0; + /** + * Requests VM to request this JIT to synchronously (in the same thread) compile given method. + * @param method method to compile + * @return true on successful compilation, false otherwise + */ + bool compileMethod(MethodDesc *method); - enum VmCallingConvention { - CallingConvention_Drl = 0, - CallingConvention_Stdcall, - CallingConvention_Cdecl, - Num_CallingConvention - }; + // returns the method to compile + MethodDesc* getMethodToCompile() const {return methodToCompile;} - // - // Returns the calling convention for managed code. - // - virtual VmCallingConvention getManagedCallingConvention() = 0; - virtual VmCallingConvention getRuntimeHelperCallingConvention(RuntimeHelperId id) = 0; + TypeManager& getTypeManager() const {return typeManager;} + MemoryManager& getMemManager() const {return memManager;} - /** - * Requests VM to request this JIT to synchronously (in the same thread) compile given method. - * @param method method to compile - * @return true on successful compilation, false otherwise - */ - virtual bool compileMethod(MethodDesc *method) = 0; + Type* getTypeFromDrlVMTypeHandle(Type_Info_Handle); - /** - * @param method JIT internal method descriptor - * @return runtime handle of the corresponding VM object for the method - */ - virtual void* getRuntimeMethodHandle(MethodDesc *method) = 0; + FieldDesc* getFieldDesc(Field_Handle field); + MethodDesc* getMethodDesc(Method_Handle method); - virtual CompilationContext* getCompilationContext() const {return compilationContext;} + void setCompilationContext(CompilationContext* cc) {compilationContext = cc;} -protected: + CompilationContext* getCompilationContext() const {return compilationContext;} + +private: /** Settings per compilation session: vminterface + optimizer flags and so on.. - * Today we pass compilation interface through the all compilation. To avoid global - * changes in JIT subcomponents interfaces CompilationContext struct is placed here. - */ + * Today we pass compilation interface through the all compilation. To avoid global + * changes in JIT subcomponents interfaces CompilationContext struct is placed here. + */ CompilationContext* compilationContext; -}; -class DataInterface { -public: - virtual ~DataInterface() {} + VM_RT_SUPPORT translateHelperId(RuntimeHelperId runtimeHelperId); + JIT_Handle getJitHandle() const; + MethodDesc* getMethodDesc(Method_Handle method, JIT_Handle jit); - // - // returns true if instance fields that are references are compressed - // - virtual bool areReferencesCompressed() = 0; - // - // returns the base for the heap (addend to compressed heap references) - // - virtual void* getHeapBase() = 0; + MemoryManager& memManager; + PtrHashTable* fieldDescs; + PtrHashTable* methodDescs; + TypeManager& typeManager; + MethodDesc* methodToCompile; + Compile_Handle compileHandle; + bool flushToZeroAllowed; + uint32 nextMemberId; + OpenMethodExecutionParams& compilation_params; }; - class GCInterface { public: + GCInterface(GC_Enumeration_Handle gcHandle) : gcHandle(gcHandle) {} virtual ~GCInterface() {} - virtual void enumerateRootReference(void** reference) = 0; - virtual void enumerateCompressedRootReference(uint32* reference) = 0; - virtual void enumerateRootManagedReference(void** slotReference, int slotOffset) = 0; -}; + virtual void enumerateRootReference(void** reference) { + vm_enumerate_root_reference(reference, FALSE); + } + virtual void enumerateCompressedRootReference(uint32* reference) { + vm_enumerate_compressed_root_reference(reference, FALSE); + } + virtual void enumerateRootManagedReference(void** slotReference, int slotOffset) { + vm_enumerate_root_interior_pointer(slotReference, slotOffset, FALSE); + } -class BinaryRewritingInterface { +private: + GC_Enumeration_Handle gcHandle; +}; + + +class ThreadDumpEnumerator : public GCInterface { public: - virtual ~BinaryRewritingInterface() {} + ThreadDumpEnumerator() : GCInterface(NULL) {} - virtual void rewriteCodeBlock(Byte* codeBlock, Byte* newCode, size_t length) = 0; + virtual void enumerateRootReference(void** reference) { + vm_check_if_monitor(reference, 0, 0, 0, FALSE, 1); + } + + virtual void enumerateCompressedRootReference(uint32* reference) { + vm_check_if_monitor(0, 0, reference, 0, FALSE, 2); + } + + virtual void enumerateRootManagedReference(void** slotReference, int slotOffset) { + vm_check_if_monitor(slotReference, 0, 0, slotOffset, FALSE, 3); + } }; -class Compiler { +// +// The Persistent Instruction Id is used to generate a profile instruction map and to +// feedback profile information into Jitrino. +// +class PersistentInstructionId { public: - virtual ~Compiler() {} + PersistentInstructionId() + : methodDesc(NULL), localInstructionId((uint32)-1) {} - // - // Return true if the method has been successfully compiled, - // false - otherwise - // - virtual bool compileMethod(CompilationInterface*) = 0; + PersistentInstructionId(MethodDesc* methodDesc, uint32 localInstructionId) + : methodDesc(methodDesc), localInstructionId(localInstructionId) {} + + bool isValid() const { return (methodDesc != NULL); } + + MethodDesc& getMethodDesc() const { return *methodDesc; } + uint32 getLocalInstructionId() const { return localInstructionId; } + + // For IPF codegen to store block ids into pid + bool hasValidLocalInstructionId() const { return localInstructionId != (uint32)-1; } + + bool operator==(const PersistentInstructionId& pid) { return methodDesc == pid.methodDesc && localInstructionId == pid.localInstructionId; } +private: + MethodDesc* methodDesc; // The source method at point the id was generated + uint32 localInstructionId; // The persistent local instruction id }; -// assert which works even in release mode -#define jitrino_assert(compInterface, e) { if (!(e)) { compInterface.hardAssert("Assertion failed", __LINE__, __FILE__); } } +inline ::std::ostream& operator<<(::std::ostream& os, const PersistentInstructionId& pid) { + os << (pid.isValid() ? pid.getMethodDesc().getName() : "NULL") << ":" + << (unsigned int) pid.getLocalInstructionId(); + return os; +} } //namespace Jitrino Index: vm/jitrino/src/main/Jitrino.cpp =================================================================== --- vm/jitrino/src/main/Jitrino.cpp (revision 523181) +++ vm/jitrino/src/main/Jitrino.cpp (working copy) @@ -31,9 +31,9 @@ #include "Log.h" #include "CountWriters.h" #include "XTimer.h" -#include "DrlVMInterface.h" +#include "VMInterface.h" -#ifndef PLATFORM_POSIX +#ifdef _WIN32 #pragma pack(push) #include #define vsnprintf _vsnprintf @@ -42,7 +42,8 @@ #include #include #include -#endif //PLATFORM_POSIX +#endif + #include "CGSupport.h" #include "PlatformDependant.h" #include "JITInstanceContext.h" @@ -78,7 +79,7 @@ void initialize_parameters(CompilationContext* compilationContext, MethodDesc &md) { // BCMap Info Required - ((DrlVMCompilationInterface*)(compilationContext->getVMCompilationInterface()))->setBCMapInfoRequired(true); + compilationContext->getVMCompilationInterface()->setBCMapInfoRequired(true); // do onetime things if (!initialized_parameters) { @@ -347,10 +348,9 @@ #endif bool -Jitrino::RecompiledMethodEvent(BinaryRewritingInterface & binaryRewritingInterface, - MethodDesc * recompiledMethodDesc, +Jitrino::RecompiledMethodEvent(MethodDesc * recompiledMethodDesc, void * data) { - return runtimeInterface->recompiledMethodEvent(binaryRewritingInterface, recompiledMethodDesc, data); + return runtimeInterface->recompiledMethodEvent(recompiledMethodDesc, data); } bool Index: vm/jitrino/src/main/PMF.cpp =================================================================== --- vm/jitrino/src/main/PMF.cpp (revision 523181) +++ vm/jitrino/src/main/PMF.cpp (working copy) @@ -24,7 +24,6 @@ #include "PMFAction.h" #include "FixFileName.h" #include "JITInstanceContext.h" -#include "open/vm.h" #include #include #include Index: vm/jitrino/src/main/Jitrino.h =================================================================== --- vm/jitrino/src/main/Jitrino.h (revision 523181) +++ vm/jitrino/src/main/Jitrino.h (working copy) @@ -24,23 +24,15 @@ #ifndef _JITRINO_H_ #define _JITRINO_H_ -#include "open/types.h" -#include "jit_export.h" #include "VMInterface.h" #include "Stl.h" -#include -// this 'ifndef' makes Jitrino (in jitrino_dev branch) build successfully both on -// Q2-05 and jitrino_dev versions of VM headers -// to be removed as soon as Q2-05 VM headers are NOT needed -// -#ifndef INLINE_INFO_PTR -#define INLINE_INFO_PTR -typedef void * InlineInfoPtr; -#endif - namespace Jitrino { +// assert which works even in release mode +// prints message, something about line and file, and hard-exits +#define jitrino_assert(e) { if (!(e)) { crash("Assertion failed at %s:%d", __FILE__ ,__LINE__); } } + void crash (const char* fmt, ...); class MemoryManager; @@ -64,8 +56,7 @@ #ifdef USE_SECURITY_OBJECT static void* GetAddressOfSecurityObject(MethodDesc* methodDesc, const ::JitFrameContext* context); #endif - static bool RecompiledMethodEvent(BinaryRewritingInterface& binaryRewritingInterface, - MethodDesc * recompiledMethodDesc, void * data); + static bool RecompiledMethodEvent(MethodDesc * recompiledMethodDesc, void * data); static MemoryManager& getGlobalMM() { return *global_mm; } static bool GetBcLocationForNative(MethodDesc* method, uint64 native_pc, uint16 *bc_pc); Index: vm/jitrino/src/main/JITInstanceContext.h =================================================================== --- vm/jitrino/src/main/JITInstanceContext.h (revision 523181) +++ vm/jitrino/src/main/JITInstanceContext.h (working copy) @@ -22,7 +22,7 @@ #ifndef _JIT_INSTANCE_CONTEXT_H_ #define _JIT_INSTANCE_CONTEXT_H_ -#include "jit_export.h" +#include "open/em.h" #include "MemoryManager.h" #include Index: vm/jitrino/src/main/PMFAction.h =================================================================== --- vm/jitrino/src/main/PMFAction.h (revision 523181) +++ vm/jitrino/src/main/PMFAction.h (working copy) @@ -22,7 +22,7 @@ #ifndef _PMFACTION_H_ #define _PMFACTION_H_ -#include "PMF.h" // sorry ... +#include "PMF.h" #include Index: vm/jitrino/src/shared/PrintDotFile.h =================================================================== --- vm/jitrino/src/shared/PrintDotFile.h (revision 523181) +++ vm/jitrino/src/shared/PrintDotFile.h (working copy) @@ -15,16 +15,6 @@ * limitations under the License. */ -/** - * @author Intel, Mikhail Y. Fursov - * @version $Revision: 1.10.24.4 $ - * - */ - -// -// interface to print dot files, you should subclass this class and -// override the method printDotBody() -// #ifndef _PRINTDOTFILE_ #define _PRINTDOTFILE_ // @@ -32,7 +22,7 @@ // implement the printBody() method // -#include +#include namespace Jitrino { Index: vm/jitrino/src/shared/Type.cpp =================================================================== --- vm/jitrino/src/shared/Type.cpp (revision 523181) +++ vm/jitrino/src/shared/Type.cpp (working copy) @@ -25,6 +25,7 @@ #include "Opnd.h" #include "Type.h" #include "VMInterface.h" +#include "PlatformDependant.h" namespace Jitrino { @@ -341,6 +342,7 @@ tauType=voidType=booleanType=charType=intPtrType=int8Type=int16Type=NULL; int32Type=int64Type=uintPtrType=uint8Type=uint16Type=NULL; uint32Type=uint64Type=singleType=doubleType=floatType=NULL; + systemObjectVMTypeHandle = systemClassVMTypeHandle = systemStringVMTypeHandle = NULL; } NamedType* @@ -354,17 +356,11 @@ } void -TypeManager::init(CompilationInterface &compInt) { - init(); - areReferencesCompressed = compInt.areReferencesCompressed(); -} - -void TypeManager::init() { - areReferencesCompressed = false; - void* systemStringVMTypeHandle = getSystemStringVMTypeHandle(); - void* systemObjectVMTypeHandle = getSystemObjectVMTypeHandle(); - void* systemClassVMTypeHandle = getSystemClassVMTypeHandle(); + areReferencesCompressed = VMInterface::areReferencesCompressed(); + void* systemStringVMTypeHandle = VMInterface::getSystemStringVMTypeHandle(); + void* systemObjectVMTypeHandle = VMInterface::getSystemObjectVMTypeHandle(); + void* systemClassVMTypeHandle = VMInterface::getSystemClassVMTypeHandle(); theSystemStringType = new (memManager) ObjectType(Type::SystemString,systemStringVMTypeHandle,*this); theSystemObjectType = new (memManager) @@ -423,7 +419,7 @@ isUnboxed = false; } if (arrayVMTypeHandle == NULL) { - arrayVMTypeHandle = getArrayVMTypeHandle(elemNamedType->getVMTypeHandle(),isUnboxed); + arrayVMTypeHandle = VMInterface::getArrayVMTypeHandle(elemNamedType->getVMTypeHandle(),isUnboxed); } type = new (memManager) ArrayType(elemNamedType,arrayVMTypeHandle,*this, isCompressed); @@ -439,11 +435,11 @@ ObjectType* TypeManager::getObjectType(void* vmTypeHandle, bool isCompressed) { - if (isArrayType(vmTypeHandle)) { - void* elemClassHandle = getArrayElemVMTypeHandle(vmTypeHandle); + if (VMInterface::isArrayType(vmTypeHandle)) { + void* elemClassHandle = VMInterface::getArrayElemVMTypeHandle(vmTypeHandle); assert(elemClassHandle != NULL); NamedType* elemType; - if (isArrayOfPrimitiveElements(vmTypeHandle)) { + if (VMInterface::isArrayOfPrimitiveElements(vmTypeHandle)) { elemType = getValueType(elemClassHandle); } else { elemType = getObjectType(elemClassHandle, areReferencesCompressed); @@ -465,9 +461,9 @@ TypeManager::getValueType(void* vmTypeHandle) { NamedType* type = userValueTypes.lookup(vmTypeHandle); if (type == NULL) { - if (isEnumType(vmTypeHandle)) { - Type* underlyingType = getUnderlyingType(vmTypeHandle); - type = new (memManager) EnumType(vmTypeHandle,*this,underlyingType); + if (/*FIXME ?? VMInterface::isEnumType(vmTypeHandle)*/ false) { + //Type* underlyingType = getUnderlyingType(vmTypeHandle); + //type = new (memManager) EnumType(vmTypeHandle,*this,underlyingType); } else { type = new (memManager) UserValueType(vmTypeHandle,*this); } @@ -478,52 +474,47 @@ bool ObjectType::_isFinalClass() { - return typeManager.isFinalType(vmTypeHandle); + return VMInterface::isFinalType(vmTypeHandle); } bool ObjectType::isInterface() { - return typeManager.isInterfaceType(vmTypeHandle); + return VMInterface::isInterfaceType(vmTypeHandle); } bool ObjectType::isAbstract() { - return typeManager.isAbstractType(vmTypeHandle); + return VMInterface::isAbstractType(vmTypeHandle); } bool NamedType::needsInitialization(){ - return typeManager.needsInitialization(vmTypeHandle); + return VMInterface::needsInitialization(vmTypeHandle); } bool NamedType::isFinalizable(){ - return typeManager.isFinalizable(vmTypeHandle); + return VMInterface::isFinalizable(vmTypeHandle); } bool NamedType::isBeforeFieldInit() { - return typeManager.isBeforeFieldInit(vmTypeHandle); + return VMInterface::isBeforeFieldInit(vmTypeHandle); } bool NamedType::isLikelyExceptionType() { - return typeManager.isLikelyExceptionType(vmTypeHandle); + return VMInterface::isLikelyExceptionType(vmTypeHandle); } -bool -NamedType::isVariableSizeType() { - return typeManager.isVariableSizeType(vmTypeHandle); -} - void* NamedType::getRuntimeIdentifier() { - return typeManager.getRuntimeClassHandle(vmTypeHandle); + return vmTypeHandle; } ObjectType* ObjectType::getSuperType() { - void* superTypeVMTypeHandle = typeManager.getSuperTypeVMTypeHandle(vmTypeHandle); + void* superTypeVMTypeHandle = VMInterface::getSuperTypeVMTypeHandle(vmTypeHandle); if (superTypeVMTypeHandle) return typeManager.getObjectType(superTypeVMTypeHandle, isCompressedReference()); @@ -537,7 +528,7 @@ // void* ObjectType::getVTable() { - return typeManager.getVTable(vmTypeHandle); + return VMInterface::getVTable(vmTypeHandle); } // @@ -545,14 +536,14 @@ // void* ObjectType::getAllocationHandle() { - return typeManager.getAllocationHandle(vmTypeHandle); + return VMInterface::getAllocationHandle(vmTypeHandle); } // // returns true if this type is a subclass of otherType // bool ObjectType::isSubClassOf(NamedType *other) { - return typeManager.isSubClassOf(vmTypeHandle,other->getRuntimeIdentifier()); + return VMInterface::isSubClassOf(vmTypeHandle,other->getRuntimeIdentifier()); } // @@ -622,35 +613,27 @@ // uint32 ObjectType::getObjectSize() { - return typeManager.getBoxedSize(vmTypeHandle); + return VMInterface::getObjectSize(vmTypeHandle); } -// -// for boxed value types, returns byte offset of the un-boxed value -// -uint32 -ObjectType::getUnboxedOffset() { - return typeManager.getUnboxedOffset(vmTypeHandle); -} - const char* ObjectType::getName() { - return typeManager.getTypeName(vmTypeHandle); + return VMInterface::getTypeName(vmTypeHandle); } const char* ObjectType::getNameQualifier() { - return typeManager.getTypeNameQualifier(vmTypeHandle); + return VMInterface::getTypeNameQualifier(vmTypeHandle); } bool ObjectType::getFastInstanceOfFlag() { - return typeManager.getClassFastInstanceOfFlag(vmTypeHandle); + return VMInterface::getClassFastInstanceOfFlag(vmTypeHandle); } int ObjectType::getClassDepth() { - return typeManager.getClassDepth(vmTypeHandle); + return VMInterface::getClassDepth(vmTypeHandle); } // @@ -659,7 +642,7 @@ uint32 ArrayType::getArrayElemOffset() { bool isUnboxed = elemType->isValueType(); - return typeManager.getArrayElemOffset(elemType->getVMTypeHandle(),isUnboxed); + return VMInterface::getArrayElemOffset(elemType->getVMTypeHandle(),isUnboxed); } // @@ -667,7 +650,7 @@ // uint32 ArrayType::getArrayLengthOffset() { - return typeManager.getArrayLengthOffset(); + return VMInterface::getArrayLengthOffset(); } // predefined value types @@ -700,40 +683,14 @@ const char* UserValueType::getName() { - return typeManager.getTypeName(vmTypeHandle); + return VMInterface::getTypeName(vmTypeHandle); } const char* UserValueType::getNameQualifier() { - return typeManager.getTypeNameQualifier(vmTypeHandle); + return VMInterface::getTypeNameQualifier(vmTypeHandle); } -uint32 -UserValueType::getUnboxedSize() { - return typeManager.getUnboxedSize(vmTypeHandle); -} - -uint32 -UserValueType::getUnboxedAlignment() { - return typeManager.getUnboxedAlignment(vmTypeHandle); -} - -// -// returns the number of fields in the value type -// -uint32 -UserValueType::getUnboxedNumFields() { - return typeManager.getUnboxedNumFields(vmTypeHandle); -} - -// -// returns the field with the given index -// -FieldDesc* -UserValueType::getUnboxedFieldDesc(uint32 index) { - return typeManager.getUnboxedFieldDesc(vmTypeHandle,index); -} - //----------------------------------------------------------------------------- // Method for printing types. Move to an IRPrinter file. //----------------------------------------------------------------------------- @@ -828,7 +785,7 @@ Type* MethodPtrType::getParamType(uint32 i) { - return (i==0 && object ? typeManager.getSingletonType(object) : methodSig->getParamType(i)); + return (i==0 && object ? typeManager.getSingletonType(object) : methodDesc->getParamType(i)); } void MethodPtrType::print(::std::ostream& os) { @@ -837,7 +794,7 @@ } else { os << "method:"; } - os << massageStr(typeManager.getMethodName(methodDesc)); + os << massageStr(methodDesc->getName()); } void VTablePtrType::print(::std::ostream& os) { Index: vm/jitrino/src/shared/Exceptions.h =================================================================== --- vm/jitrino/src/shared/Exceptions.h (revision 523181) +++ vm/jitrino/src/shared/Exceptions.h (working copy) @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author Intel, Mikhail Y. Fursov - * @version $Revision: 1.6.24.4 $ - * - */ - -#ifndef _EXCEPTIONS_H_ -#define _EXCEPTIONS_H_ - -#include "assert.h" - -class IndexOutOfBoundsException { -public: - IndexOutOfBoundsException() : msg("") { assert(0); } - IndexOutOfBoundsException(const char* message) : msg(message) { assert(0); } - const char* getMessage() {return msg;} -private: - const char* msg; -}; - -class TranslationException { -public: - TranslationException() { assert(0); } -}; - -#endif // _EXCEPTIONS_H_ Index: vm/jitrino/src/shared/PrintDotFile.cpp =================================================================== --- vm/jitrino/src/shared/PrintDotFile.cpp (revision 523181) +++ vm/jitrino/src/shared/PrintDotFile.cpp (working copy) @@ -15,24 +15,13 @@ * limitations under the License. */ -/** - * @author Intel, Mikhail Y. Fursov - * @version $Revision: 1.16.16.4 $ - * - */ +#include +#include -// -// interface to print dot files, you should subclass this class and -// implement the printBody() method -// #include "PrintDotFile.h" #include "Inst.h" #include "optimizer.h" #include "Log.h" -#include -#include -#include -#include namespace Jitrino { @@ -49,6 +38,9 @@ public: dotbuf(::std::streambuf* sb) : inquotes(false), bracedepth(0), m_sb(sb) {} +private: + // copy ctor to make msvc compiler happy + dotbuf(dotbuf& sb){} protected: int_type overflow(int_type c) { @@ -91,6 +83,9 @@ ::std::ostream(&m_buf), m_buf(out.rdbuf()) {} private: + // copy ctor to make msvc compiler happy + dotstream(dotstream& sb) : ::std::ostream(NULL), m_buf(NULL) {} + dotbuf m_buf; }; Index: vm/jitrino/src/shared/PlatformDependant.h =================================================================== --- vm/jitrino/src/shared/PlatformDependant.h (revision 523181) +++ vm/jitrino/src/shared/PlatformDependant.h (working copy) @@ -36,6 +36,10 @@ #define strdup _strdup #define strcmpi _strcmpi #define stricmp _stricmp + + #define isnan _isnan + #define finite _finite + #endif //_MSC_VER #undef stdcall__ Index: vm/jitrino/src/shared/Type.h =================================================================== --- vm/jitrino/src/shared/Type.h (revision 523181) +++ vm/jitrino/src/shared/Type.h (working copy) @@ -32,14 +32,6 @@ namespace Jitrino { -#ifdef PLATFORM_POSIX -#ifndef __cdecl -#define __cdecl -#endif -#endif - -class MethodDesc; -class FieldDesc; class SsaOpnd; // // forward declarations @@ -262,7 +254,7 @@ return (SystemObject <= tag && tag <= ITablePtrObj); } static bool isCompressedReference(Tag tag, CompilationInterface &compInt) { - if (compInt.areReferencesCompressed()) { + if (VMInterface::areReferencesCompressed()) { // Note: When a reference is converted to a managed pointer, it is converted from a // compressed pointer in the heap to a raw pointer in the heap return ((SystemObject <= tag && tag <= BoxedValue) @@ -407,20 +399,19 @@ class MethodPtrType : public FunctionPtrType { public: MethodPtrType(MethodDesc* md, TypeManager& tm, bool isCompressed=false, ValueName obj=NULL) - : FunctionPtrType(isCompressed), methodDesc(md), methodSig(md->getMethodSig()), typeManager(tm), object(obj) {} + : FunctionPtrType(isCompressed), methodDesc(md), typeManager(tm), object(obj) {} virtual ~MethodPtrType() {} MethodPtrType* asMethodPtrType() { return this; } - uint32 getNumParams() { return methodSig->getNumParams(); } + uint32 getNumParams() { return methodDesc->getNumParams(); } Type* getParamType(uint32 i); - Type* getReturnType() { return methodSig->getReturnType(); } + Type* getReturnType() { return methodDesc->getReturnType(); } bool isInstance() { return methodDesc->isInstance(); } MethodDesc* getMethodDesc() {return methodDesc;} void print(::std::ostream& os); ValueName getThisValueName() { return object; } private: MethodDesc* methodDesc; - MethodSignatureDesc* methodSig; TypeManager& typeManager; ValueName object; }; @@ -455,7 +446,6 @@ bool isFinalizable(); bool isBeforeFieldInit(); bool isLikelyExceptionType(); - bool isVariableSizeType(); bool isNamedType() {return true;} // // Returns the runtime identifier for this type; @@ -486,16 +476,8 @@ // // returns size & alignment of the un-boxed value // - virtual uint32 getUnboxedSize(); - virtual uint32 getUnboxedAlignment(); - // - // returns the number of fields in the value type - // - virtual uint32 getUnboxedNumFields(); - // - // returns the field with the given index - // - virtual FieldDesc* getUnboxedFieldDesc(uint32 index); + virtual uint32 getUnboxedSize(){assert(0); return 0;} + //virtual uint32 getUnboxedAlignment(); void print(::std::ostream& os); protected: UserValueType(Tag t,void* td,TypeManager& tm) : NamedType(t,td,tm) {} @@ -655,9 +637,8 @@ TypeManager(MemoryManager& mm); virtual ~TypeManager() {} - void init(CompilationInterface &compInt); void init(); - MemoryManager& getMemManager() {return memManager;} + //MemoryManager& getMemManager() {return memManager;} Type* getPrimitiveType(Type::Tag); // Convert type to the type which variable will have @@ -722,10 +703,6 @@ } return type; } - Type* getFunPtrType(Type* retType,uint32 numParams,Type** paramTypes) { - assert(0); - return NULL; - } MethodPtrType* getMethodPtrType(MethodDesc* methodDesc) { MethodPtrType* type = methodPtrTypes.lookup(methodDesc); if (type == NULL) { @@ -827,7 +804,7 @@ { if (vmAllocationHandle==NULL) return NULL; - void * vmTypeHandle = getTypeHandleFromAllocationHandle(vmAllocationHandle); + void * vmTypeHandle = VMInterface::getTypeHandleFromAllocationHandle(vmAllocationHandle); if ( vmTypeHandle==NULL || vmTypeHandle>(void*)-100 || ((POINTER_SIZE_INT)vmTypeHandle&0x3)!=0 ) { @@ -895,56 +872,11 @@ bool areReferencesCompressed; NamedType* initBuiltinType(Type::Tag tag); -public: - // - // VM specific methods for types - // Move to VM interface class and delegate - // - virtual void* getBuiltinValueTypeVMTypeHandle(Type::Tag) = 0; - virtual void* getSystemObjectVMTypeHandle() = 0; - virtual void* getSystemClassVMTypeHandle() = 0; - virtual void* getSystemStringVMTypeHandle() = 0; - virtual void* getArrayVMTypeHandle(void* elemVMTypeHandle,bool isUnboxed) = 0; - virtual const char* getTypeName(void* vmTypeHandle) = 0; - virtual const char* getTypeNameQualifier(void* vmTypeHandle) = 0; - virtual void* getSuperTypeVMTypeHandle(void* vmTypeHandle) = 0; - virtual const char* getMethodName(MethodDesc*) = 0; - virtual void* getArrayElemVMTypeHandle(void* vmTypeHandle) = 0; - virtual bool isArrayType(void* vmTypeHandle) = 0; - virtual bool isArrayOfPrimitiveElements(void* vmTypeHandle) = 0; - virtual bool isEnumType(void* vmTypeHandle) = 0; - virtual bool isValueType(void* vmTypeHandle) = 0; - virtual bool isFinalType(void* vmTypeHandle) = 0; - virtual bool isLikelyExceptionType(void* vmTypeHandle) = 0; - virtual bool isInterfaceType(void* vmTypeHandle) = 0; - virtual bool isAbstractType(void* vmTypeHandle) = 0; - virtual bool isSystemStringType(void* vmTypeHandle) = 0; - virtual bool isSystemObjectType(void* vmTypeHandle) = 0; - virtual bool isSystemClassType(void* vmTypeHandle) = 0; - virtual bool needsInitialization(void* vmTypeHandle) = 0; - virtual bool isFinalizable(void* vmTypeHandle) = 0; - virtual bool isBeforeFieldInit(void* vmTypeHandle) = 0; - virtual bool getClassFastInstanceOfFlag(void* vmTypeHandle) = 0; - virtual int getClassDepth(void* vmTypeHandle) = 0; - virtual bool isInitialized(void* vmTypeHandle) = 0; - virtual bool isVariableSizeType(void* vmTypeHandle) = 0; - virtual void* getVTable(void* vmTypeHandle) = 0; - virtual void* getRuntimeClassHandle(void* vmTypeHandle) = 0; - virtual void* getAllocationHandle(void* vmTypeHandle) = 0; - virtual bool isSubClassOf(void* vmTypeHandle1,void* vmTypeHandle2) = 0; - virtual uint32 getUnboxedOffset(void* vmTypeHandle) = 0; - virtual uint32 getArrayElemOffset(void* vmElemTypeHandle,bool isUnboxed) = 0; - virtual uint32 getBoxedSize(void * vmTypeHandle) = 0; - virtual uint32 getUnboxedSize(void* vmTypeHandle) = 0; - virtual uint32 getUnboxedAlignment(void* vmTypeHandle) = 0; - virtual uint32 getUnboxedNumFields(void* vmTypeHandle) = 0; - virtual FieldDesc* getUnboxedFieldDesc(void* vmTypeHandle,uint32 index) = 0; - virtual uint32 getArrayLengthOffset() = 0; - virtual Type* getUnderlyingType(void* enumVMTypeHandle) = 0; + void* getBuiltinValueTypeVMTypeHandle(Type::Tag); - virtual uint32 getVTableOffset() = 0; - virtual void* getTypeHandleFromAllocationHandle(void* vmAllocationHandle) = 0; - + void* systemObjectVMTypeHandle; + void* systemClassVMTypeHandle; + void* systemStringVMTypeHandle; }; } //namespace Jitrino Index: vm/jitrino/src/shared/methodtable.cpp =================================================================== --- vm/jitrino/src/shared/methodtable.cpp (revision 523181) +++ vm/jitrino/src/shared/methodtable.cpp (working copy) @@ -56,7 +56,6 @@ // FOO=(Ljava/lang/Object;) // FOO=(L;) (jit only methods with a single class ptr in signature) -//#include "defines.h" #include #include #include Index: vm/jitrino/src/translator/java/JavaByteCodeTranslator.h =================================================================== --- vm/jitrino/src/translator/java/JavaByteCodeTranslator.h (revision 523181) +++ vm/jitrino/src/translator/java/JavaByteCodeTranslator.h (working copy) @@ -268,7 +268,7 @@ // // helper methods for generating code // - Opnd** popArgs(MethodSignatureDesc*); + Opnd** popArgs(uint32 numArgs); // for invoke emulation if resolution fails void pseudoInvoke(const char* mdesc); void invalid(); // called when invalid IR is encountered Index: vm/jitrino/src/translator/java/JavaLabelPrepass.cpp =================================================================== --- vm/jitrino/src/translator/java/JavaLabelPrepass.cpp (revision 523181) +++ vm/jitrino/src/translator/java/JavaLabelPrepass.cpp (working copy) @@ -284,7 +284,7 @@ } } -class JavaExceptionParser: public ExceptionCallback { +class JavaExceptionParser { public: JavaExceptionParser(MemoryManager& mm,JavaLabelPrepass& p, CompilationInterface& ci,MethodDesc* method) @@ -292,11 +292,28 @@ compilationInterface(ci), enclosingMethod(method), prevCatch(NULL), nextRegionId(0) {} + uint32 parseHandlers() { + uint32 numHandlers = enclosingMethod->getNumHandlers(); + for (uint32 i=0; igetHandlerInfo(i,&beginOffset,&endOffset, + &handlerOffset,&handlerClassIndex); + if (!catchBlock(beginOffset,endOffset-beginOffset, + handlerOffset,0,handlerClassIndex)) + { + // handlerClass failed to be resolved. LinkingException throwing helper + // will be generated instead of method's body + return handlerClassIndex; + } + } + return MAX_UINT32; // all catchBlocks were processed successfully + } + void addHandlerForCatchBlock(CatchBlock* block, uint32 handlerOffset, uint32 handlerLength, Type* exceptionType) { - jitrino_assert(compilationInterface, exceptionType); + jitrino_assert( exceptionType); Log::out() << "Catch Exception Type = " << exceptionType->getName() << ::std::endl; CatchHandler* handler = new (memManager) @@ -342,7 +359,7 @@ return newBlock; } - virtual bool catchBlock(uint32 tryOffset, + bool catchBlock(uint32 tryOffset, uint32 tryLength, uint32 handlerOffset, uint32 handlerLength, @@ -419,19 +436,6 @@ } return 1; // all exceptionTypes are OK } - virtual void finallyBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength) {jitrino_assert(compilationInterface, 0);} - virtual void filterBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength, - uint32 expressionStart) {jitrino_assert(compilationInterface, 0);} - virtual void faultBlock(uint32 tryOffset, - uint32 tryLength, - uint32 handlerOffset, - uint32 handlerLength) {jitrino_assert(compilationInterface, 0);} uint32 numCatch; MemoryManager& memManager; @@ -490,7 +494,7 @@ // parse and create exception info JavaExceptionParser exceptionTypes(irManager,*this,compilationInterface,&methodDesc); // fix exception handlers - unsigned problemToken = methodDesc.parseJavaHandlers(exceptionTypes); + unsigned problemToken = exceptionTypes.parseHandlers(); if(problemToken != MAX_UINT32) { problemTypeToken = problemToken; @@ -504,8 +508,7 @@ isFallThruLabel = true; numVars = methodDesc.getNumVars(); methodDesc.getMaxStack(); - MethodSignatureDesc* methodSig = methodDesc.getMethodSig(); - uint32 numArgs = methodSig->getNumParams(); + uint32 numArgs = methodDesc.getNumParams(); for (uint32 i=0, j=0; igetType(); if(Log::isEnabled()) { Log::out() << "PARAM " << (int)i << " sig: "; - methodSig->getParamType(i)->print(Log::out()); + methodDesc.getParamType(i)->print(Log::out()); Log::out() << " actual: "; type->print(Log::out()); Log::out() << ::std::endl; } @@ -524,7 +527,7 @@ if (Simplifier::isNonNullParameter(actual)) StateInfo::setNonNull(slot); if (Simplifier::isExactType(actual)) StateInfo::setExactType(slot); } else { - type = methodSig->getParamType(i); + type = methodDesc.getParamType(i); if (!type) { // linkage error will happen at the usage point of this parameter // here we just keep it as NullObj @@ -1152,7 +1155,7 @@ slot.type = typeManager.getNullObjectType(); } slot.vars = NULL; - jitrino_assert(compilationInterface, slot.type); + jitrino_assert( slot.type); pushType(slot); } @@ -1168,7 +1171,7 @@ case 9: elemType = typeManager.getInt16Type(); break; case 10: elemType = typeManager.getInt32Type(); break; case 11: elemType = typeManager.getInt64Type(); break; - default: jitrino_assert(compilationInterface, 0); + default: jitrino_assert( 0); } StateInfo::SlotInfo slot; StateInfo::setNonNull(&slot); @@ -1191,7 +1194,7 @@ slot.type = typeManager.getNullObjectType(); } slot.vars = NULL; - jitrino_assert(compilationInterface, slot.type); + jitrino_assert( slot.type); pushType(slot); } @@ -1212,7 +1215,7 @@ return; } popAndCheck(A); - jitrino_assert(compilationInterface, type); + jitrino_assert( type); pushType(type); } int JavaLabelPrepass::instanceof(const uint8* bcp, uint32 constPoolIndex, uint32 off) { @@ -1287,7 +1290,7 @@ } else if (constantType->isSingle()) { pushType(singleType); } else { - jitrino_assert(compilationInterface, 0); + jitrino_assert( 0); } } void JavaLabelPrepass::ldc2(uint32 constPoolIndex) { @@ -1299,7 +1302,7 @@ } else if (constantType->isDouble()) { pushType(doubleType); } else { - jitrino_assert(compilationInterface, 0); + jitrino_assert( 0); } } @@ -1409,7 +1412,7 @@ if ( !type ) { type = typeManager.getNullObjectType(); } - jitrino_assert(compilationInterface, type); + jitrino_assert( type); pushType(type); } @@ -1540,11 +1543,10 @@ } void JavaLabelPrepass::invoke(MethodDesc* methodDesc) { - MethodSignatureDesc* methodSig = methodDesc->getMethodSig(); // pop source operands - for (int i=methodSig->getNumParams()-1; i>=0; i--) + for (int i = methodDesc->getNumParams()-1; i>=0; i--) popType(); - Type* type = methodSig->getReturnType(); + Type* type = methodDesc->getReturnType(); // push the return type if (type) { if ( type->tag != Type::Void ) { @@ -1847,7 +1849,7 @@ } const char* JavaLabelPrepass::methodSignatureString(uint32 cpIndex) { - return compilationInterface.methodSignatureString(&methodDesc,cpIndex); + return compilationInterface.getSignatureString(&methodDesc,cpIndex); } void StateTable::copySlotInfo(StateInfo::SlotInfo& to, StateInfo::SlotInfo& from) { Index: vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp =================================================================== --- vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp (revision 523181) +++ vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp (working copy) @@ -446,14 +446,13 @@ void JavaByteCodeTranslator::initArgs() { - MethodSignatureDesc* methodSignatureDesc = methodToCompile.getMethodSig(); // incoming argument and return value information - numArgs = methodSignatureDesc->getNumParams(); - retType = methodSignatureDesc->getReturnType(); + numArgs = methodToCompile.getNumParams(); + retType = methodToCompile.getReturnType(); argTypes = new (memManager) Type*[numArgs]; args = new (memManager) Opnd*[numArgs]; for (uint16 i=0; igetParamType(i); + Type* argType = methodToCompile.getParamType(i); // argType == NULL if it fails to be resolved. Respective exception // will be thrown at the point of usage argTypes[i] = argType != NULL ? argType : typeManager.getNullObjectType(); @@ -602,14 +601,14 @@ const char* JavaByteCodeTranslator::methodSignatureString(uint32 cpIndex) { - return compilationInterface.methodSignatureString(&methodToCompile,cpIndex); + return compilationInterface.getSignatureString(&methodToCompile,cpIndex); } uint32 JavaByteCodeTranslator::labelId(uint32 offset) { uint32 labelId = prepass.getLabelId(offset); if (labelId == (uint32) -1) - jitrino_assert(compilationInterface, 0); + jitrino_assert(0); return labelId; } @@ -620,13 +619,13 @@ // called when invalid byte code is encountered void JavaByteCodeTranslator::invalid() { - jitrino_assert(compilationInterface,0); + jitrino_assert(0); } // called when an error occurs during the byte code parsing void JavaByteCodeTranslator::parseError() { - jitrino_assert(compilationInterface,0); + jitrino_assert(0); } void @@ -727,7 +726,7 @@ Log::out() << "LABEL "; labelInst->print(Log::out()); Log::out() << labelInst->getState(); Log::out() << "CATCH "; handler->getLabelInst()->print(Log::out()); Log::out() << ::std::endl; } - } else {jitrino_assert(compilationInterface,0);} // only catch blocks should occur in Java + } else {jitrino_assert(0);} // only catch blocks should occur in Java } // generate the label instruction if(translationFlags.newCatchHandling && !catchLabels.empty()) { @@ -1011,7 +1010,7 @@ opnd = irBuilder.genLdConstant((float)value); } else { // Invalid type! - jitrino_assert(compilationInterface,0); + jitrino_assert(0); } } pushOpnd(opnd); @@ -1034,7 +1033,7 @@ opnd = irBuilder.genLdConstant((double)value); } else { // Invalid type! - jitrino_assert(compilationInterface,0); + jitrino_assert(0); } pushOpnd(opnd); } @@ -1736,7 +1735,7 @@ //----------------------------------------------------------------------------- void JavaByteCodeTranslator::linkingException(uint32 constPoolIndex, uint32 operation) { - Class_Handle enclosingDrlVMClass = compilationInterface.methodGetClass(&methodToCompile); + Class_Handle enclosingDrlVMClass = methodToCompile.getParentHandle(); irBuilder.genThrowLinkingException(enclosingDrlVMClass, constPoolIndex, operation); } //----------------------------------------------------------------------------- @@ -1764,8 +1763,7 @@ // method invocation byte codes //----------------------------------------------------------------------------- Opnd** -JavaByteCodeTranslator::popArgs(MethodSignatureDesc* methodSignatureDesc) { - uint32 numArgs = methodSignatureDesc->getNumParams(); +JavaByteCodeTranslator::popArgs(uint32 numArgs) { // pop source operands Opnd** srcOpnds = new (memManager) Opnd*[numArgs]; for (int i=numArgs-1; i>=0; i--) @@ -1783,12 +1781,10 @@ pseudoInvoke(methodSig_string); return; } - jitrino_assert(compilationInterface,methodDesc); - MethodSignatureDesc* methodSig = methodDesc->getMethodSig(); - jitrino_assert(compilationInterface,methodSig); - Opnd** srcOpnds = popArgs(methodSig); - uint32 numArgs = methodSig->getNumParams(); - Type* returnType = methodSig->getReturnType(); + jitrino_assert(methodDesc); + uint32 numArgs = methodDesc->getNumParams(); + Opnd** srcOpnds = popArgs(numArgs); + Type* returnType = methodDesc->getReturnType(); if (isMagicClass(methodDesc->getParentType())) { genMagic(methodDesc, numArgs, srcOpnds, returnType); @@ -1928,12 +1924,10 @@ pseudoInvoke(methodSig_string); return; } - jitrino_assert(compilationInterface,methodDesc); - MethodSignatureDesc* methodSig = methodDesc->getMethodSig(); - jitrino_assert(compilationInterface,methodSig); - uint32 numArgs = methodSig->getNumParams(); - Opnd** srcOpnds = popArgs(methodSig); - Type* returnType = methodSig->getReturnType(); + jitrino_assert(methodDesc); + uint32 numArgs = methodDesc->getNumParams(); + Opnd** srcOpnds = popArgs(numArgs); + Type* returnType = methodDesc->getReturnType(); // invokespecial can throw a null pointer exception Opnd *tauNullChecked = irBuilder.genTauCheckNull(srcOpnds[0]); Opnd* dst; @@ -1990,12 +1984,10 @@ pseudoInvoke(methodSig_string); return; } - jitrino_assert(compilationInterface,methodDesc); - MethodSignatureDesc* methodSig = methodDesc->getMethodSig(); - jitrino_assert(compilationInterface,methodSig); - uint32 numArgs = methodSig->getNumParams(); - Opnd** srcOpnds = popArgs(methodSig); - Type *returnType = methodSig->getReturnType(); + jitrino_assert(methodDesc); + uint32 numArgs = methodDesc->getNumParams(); + Opnd** srcOpnds = popArgs(numArgs); + Type *returnType = methodDesc->getReturnType(); if (returnType == NULL) { // This means that it was not resolved successfully but it can be resolved later // inside the callee (with some "magic" custom class loader for example) @@ -2033,12 +2025,10 @@ pseudoInvoke(methodSig_string); return; } - jitrino_assert(compilationInterface,methodDesc); - MethodSignatureDesc* methodSig = methodDesc->getMethodSig(); - jitrino_assert(compilationInterface,methodSig); - Type* returnType = methodSig->getReturnType(); - uint32 numArgs = methodSig->getNumParams(); - Opnd** srcOpnds = popArgs(methodSig); + jitrino_assert(methodDesc); + uint32 numArgs = methodDesc->getNumParams(); + Opnd** srcOpnds = popArgs(numArgs); + Type* returnType = methodDesc->getReturnType(); // callintf can throw a null pointer exception Opnd *tauNullChecked = irBuilder.genTauCheckNull(srcOpnds[0]); Opnd* thisOpnd = srcOpnds[0]; @@ -2105,7 +2095,7 @@ pushOpnd(irBuilder.genLdNull()); return; } - jitrino_assert(compilationInterface,type); + jitrino_assert(type); pushOpnd(irBuilder.genNewObj(type)); } void @@ -2128,7 +2118,7 @@ type = typeManager.getInt32Type(); break; case 11: // long type = typeManager.getInt64Type(); break; - default: jitrino_assert(compilationInterface,0); + default: jitrino_assert(0); } Opnd* arrayOpnd = irBuilder.genNewArray(type,popOpnd()); pushOpnd(arrayOpnd); @@ -2150,7 +2140,7 @@ pushOpnd(irBuilder.genLdNull()); return; } - jitrino_assert(compilationInterface,type); + jitrino_assert(type); pushOpnd(irBuilder.genNewArray(type,popOpnd())); } @@ -2166,8 +2156,8 @@ pushOpnd(irBuilder.genLdNull()); return; } - jitrino_assert(compilationInterface,arraytype); - jitrino_assert(compilationInterface,dimensions > 0); + jitrino_assert(arraytype); + jitrino_assert(dimensions > 0); Opnd** countOpnds = new (memManager) Opnd*[dimensions]; // pop the sizes for (int i=dimensions-1; i>=0; i--) { @@ -2200,7 +2190,7 @@ linkingException(constPoolIndex, OPCODE_CHECKCAST); return; // can be left as is } - jitrino_assert(compilationInterface,type); + jitrino_assert(type); pushOpnd(irBuilder.genCast(popOpnd(),type)); } @@ -2213,7 +2203,7 @@ pushOpnd(irBuilder.genLdConstant((int32)0)); return 3; } - jitrino_assert(compilationInterface,type); + jitrino_assert(type); Opnd* src = popOpnd(); Type* srcType = src->getType(); @@ -2789,8 +2779,8 @@ bool dstIsArray = dstType->isArray(); ArrayType* srcAsArrayType = srcType->asArrayType(); ArrayType* dstAsArrayType = dstType->asArrayType(); - bool srcIsArrOfPrimitive = srcIsArray && typeManager.isArrayOfPrimitiveElements(srcAsArrayType->getVMTypeHandle()); - bool dstIsArrOfPrimitive = dstIsArray && typeManager.isArrayOfPrimitiveElements(dstAsArrayType->getVMTypeHandle()); + bool srcIsArrOfPrimitive = srcIsArray && VMInterface::isArrayOfPrimitiveElements(srcAsArrayType->getVMTypeHandle()); + bool dstIsArrOfPrimitive = dstIsArray && VMInterface::isArrayOfPrimitiveElements(dstAsArrayType->getVMTypeHandle()); if ( !(srcIsArray && dstIsArray) ) { throwsASE = true; } else if ( srcIsArrOfPrimitive ) { @@ -2804,7 +2794,7 @@ // To avoid this we just reject the inlining of System::arraycopy call in this case. NamedType* srcElemType = srcAsArrayType->getElementType(); NamedType* dstElemType = dstAsArrayType->getElementType(); - throwsASE = ! typeManager.isSubClassOf(srcElemType->getVMTypeHandle(),dstElemType->getVMTypeHandle()); + throwsASE = ! VMInterface::isSubClassOf(srcElemType->getVMTypeHandle(),dstElemType->getVMTypeHandle()); } if ( throwsASE ) return false; Index: vm/jitrino/src/translator/java/JavaByteCodeParser.cpp =================================================================== --- vm/jitrino/src/translator/java/JavaByteCodeParser.cpp (revision 523181) +++ vm/jitrino/src/translator/java/JavaByteCodeParser.cpp (working copy) @@ -22,7 +22,6 @@ */ #include -#include "assert.h" #include "JavaByteCodeParser.h" namespace Jitrino { Index: vm/jitrino/src/translator/TranslatorIntfc.cpp =================================================================== --- vm/jitrino/src/translator/TranslatorIntfc.cpp (revision 523181) +++ vm/jitrino/src/translator/TranslatorIntfc.cpp (working copy) @@ -51,18 +51,14 @@ IRManager* irm = cc->getHIRManager(); assert(irm); MethodDesc& methodDesc = irm->getMethodDesc(); - if (methodDesc.isJavaByteCodes()) { - //create IRBuilder - MemoryManager& mm = cc->getCompilationLevelMemoryManager(); - TranslatorAction* myAction = (TranslatorAction*)getAction(); - IRBuilder* irb = (IRBuilder*)myAction->getIRBuilderAction()->createSession(mm); - irb->setCompilationContext(cc); - MemoryManager tmpMM(1024, "IRBuilder::tmpMM"); - irb->init(irm, &flags, tmpMM); - JavaTranslator::translateMethod(*cc->getVMCompilationInterface(), methodDesc, *irb); - } else { - assert(false); - } + //create IRBuilder + MemoryManager& mm = cc->getCompilationLevelMemoryManager(); + TranslatorAction* myAction = (TranslatorAction*)getAction(); + IRBuilder* irb = (IRBuilder*)myAction->getIRBuilderAction()->createSession(mm); + irb->setCompilationContext(cc); + MemoryManager tmpMM(1024, "IRBuilder::tmpMM"); + irb->init(irm, &flags, tmpMM); + JavaTranslator::translateMethod(*cc->getVMCompilationInterface(), methodDesc, *irb); } Index: vm/jitrino/src/dynopt/EdgeProfiler.cpp =================================================================== --- vm/jitrino/src/dynopt/EdgeProfiler.cpp (revision 523181) +++ vm/jitrino/src/dynopt/EdgeProfiler.cpp (working copy) @@ -21,9 +21,8 @@ * @version $Revision$ */ - +#include "EMInterface.h" #include "Jitrino.h" -#include "EdgeProfiler.h" #include "Inst.h" #include "Stl.h" #include "StaticProfiler.h" Index: vm/jitrino/src/dynopt/EdgeProfiler.h =================================================================== --- vm/jitrino/src/dynopt/EdgeProfiler.h (revision 523181) +++ vm/jitrino/src/dynopt/EdgeProfiler.h (working copy) @@ -1,35 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* COPYRIGHT_NOTICE */ -/** -* @author Jack Liu, Mikhail Y. Fursov, Chen-Dong Yuan -* @version $Revision$ -*/ - - -#include "Jitrino.h" -#include "irmanager.h" -#include "VMInterface.h" -#include "EMInterface.h" -#include "optpass.h" - -#include - - -namespace Jitrino { - //todo: remove this file -}