Exemple #1
0
	void CoerceInstruction::print() {
		char buffer[128];
		char typeOfInstruction[32];
		char coerceResult[32];

		if (this->isConvert()) {
			VMPI_snprintf(typeOfInstruction, sizeof(typeOfInstruction), "ConvertInstruction");
		} else {
			VMPI_snprintf(typeOfInstruction, sizeof(typeOfInstruction), "CoerceInstruction");
		}

		if (this->isMultinameCoerce()) {
			avmplus::Stringp coerceType = this->multinameToCoerce->getName();
			StUTF8String utf8String(coerceType );
			const char* stringValue = utf8String.c_str();
			VMPI_snprintf(coerceResult, sizeof(coerceResult), "%s", stringValue);
		} else {
			VMPI_snprintf(coerceResult, sizeof(coerceResult), "%s", this->getTypeToCoerce()->toString().data());
		}

		VMPI_snprintf(buffer, sizeof(buffer), "%s %s (%s) -> %s", this->getPrintPrefix().c_str(),
			typeOfInstruction, _instructionToCoerce->getOperandString().c_str(), coerceResult);

		printf("%s\n", buffer);
	}
Exemple #2
0
	void ConsistencyChecker::checkAllBlocksWithMultiplePredecessorsHavePhi() {
		List<BasicBlock*, LIST_GCObjects>* basicBlocks = _functionToCheck->getBasicBlocksInReversePostOrder();
		TessaAssert(basicBlocks != NULL);
		char messageBuffer[64];
		for (uint32_t i = 0; i < basicBlocks->size(); i++) {
			BasicBlock* currentBasicBlock = basicBlocks->get(i);
			
			if (currentBasicBlock->getPredecessors()->size() > 1) {
				List<TessaInstruction*, LIST_GCObjects>* instructions = currentBasicBlock->getInstructions();

				for (uint32_t j = 0; j < instructions->size(); j++) {
					TessaInstruction* instruction = instructions->get(j);
					if (instruction->isParameter()) {
						ParameterInstruction* paramInstruction = (ParameterInstruction*) instruction;
						TessaInstruction* forwardInstruction = paramInstruction->resolve();

						VMPI_snprintf(messageBuffer, sizeof(messageBuffer), "BB %d Param %d does not map to Phi \n", currentBasicBlock->getBasicBlockId(), paramInstruction->getValueId());
						TessaAssertMessage(forwardInstruction->isPhi(), messageBuffer);

						if (!forwardInstruction->isPhi()) {
							printf("%s\n", messageBuffer);
						}
					}
				}
			}
		}
	}
Exemple #3
0
void* OpenAndConnectToNamedPipe(const char *pipeName)
{
	char name[256];
	VMPI_snprintf(name, sizeof(name), "\\\\.\\pipe\\%s", pipeName);

	HANDLE pipe = CreateNamedPipeA((LPCSTR)name, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 4096, 4096, 100, NULL);
	ConnectNamedPipe(pipe, NULL);
	return (void*)pipe;
}
	void UnconditionalBranchInstruction::print() {
		int targetBasicBlockId = _branchTarget->getBasicBlockId();
		//int targetBasicBlockId = 5;
		char buffer[64];
		VMPI_snprintf(buffer, sizeof(buffer), "%s UnconditionalBranch BB%d\n", 
			this->getPrintPrefix().c_str(), targetBasicBlockId);

		printf("%s", buffer);
	}
Exemple #5
0
	void UnaryInstruction::print() {
		TessaAssert(opcode < ((sizeof(TessaUnaryOpNames) / sizeof(char*)) ));
		char buffer[512];
		VMPI_snprintf(buffer, sizeof(buffer), "%s UnaryInstruction %s %s -> (Type %s) \n", getPrintPrefix().c_str(), TessaUnaryOpNames[opcode], 
			operand->getOperandString().c_str(),
			getType()->toString().data()
			);
		printf("%s", buffer);
	}
Exemple #6
0
 VMThread::VMThread(Runnable* runnable)
     : m_runnable(runnable)
     , m_state(NOT_STARTED)
     , m_joinerQty(0)
 {
     int suffix = m_nextNameSuffix.incAndGet();
     char buf[64];
     VMPI_snprintf(buf, sizeof(buf), "Thread-%d", suffix);
     setNameFrom(buf);
 }
Exemple #7
0
 VMThread::VMThread()
     : m_threadID(VMPI_nullThread()) // CID:12562 Uninitialized scalar field
     , m_state(NOT_STARTED)
     , m_joinerQty(0)
 {
     m_runnable = this;
     int suffix = m_nextNameSuffix.incAndGet();
     char buf[64];
     VMPI_snprintf(buf, sizeof(buf), "Thread-%d", suffix);
     setNameFrom(buf);
 }
Exemple #8
0
	bool ConsistencyChecker::phiOperandsExistsInPredecessorBlock(PhiInstruction* phiInstruction) {
		BasicBlock* parentBlock = phiInstruction->getInBasicBlock();
		int numberOfOperands = phiInstruction->numberOfOperands();
		char errorMessage[256];

		for (int i = 0; i < numberOfOperands; i++) {
			BasicBlock* operandBlock = phiInstruction->getIncomingEdge(i);
			TessaInstruction* phiOperand = phiInstruction->getOperand(operandBlock);
			BasicBlock* phiOperandBlock = phiOperand->getInBasicBlock();

			VMPI_snprintf(errorMessage, sizeof(errorMessage), "Phi %d has operand %d with incoming block %d, but operand does not exist in block\n\n",
					phiInstruction->getValueId(), phiOperand->getValueId(), operandBlock->getBasicBlockId());
			AvmAssertMsg(operandBlock == phiOperandBlock, errorMessage);
		}

		return true;
	}
Exemple #9
0
	bool ConsistencyChecker::allPhiOperandsArePredecessors(PhiInstruction* phiInstruction) {
		BasicBlock* parentBlock = phiInstruction->getInBasicBlock();
		int numberOfOperands = phiInstruction->numberOfOperands();
		char errorMessage[64];

		for (int i = 0; i < numberOfOperands; i++) {
			BasicBlock* operandBlock = phiInstruction->getIncomingEdge(i);
			List<BasicBlock*, LIST_GCObjects>* successors = operandBlock->getSuccessors();
			if (!successors->contains(parentBlock)) { 
				VMPI_snprintf(errorMessage, sizeof(errorMessage), "Phi %d has incoming block %d, but block is not a predecessor\n", 
					phiInstruction->getValueId(), operandBlock->getBasicBlockId());
				printf(errorMessage);
				return false;
			}
		}

		return true;
	}
Exemple #10
0
	void ConsistencyChecker::checkAllBlocksHaveTerminators() {
		/*** 
		 * Have to do reverse post order because some blocks may be dead due to weird control flow (breaks/continue statements)
		 */
		List<BasicBlock*, LIST_GCObjects>* basicBlocks = _functionToCheck->getBasicBlocksInReversePostOrder();
		TessaAssert(basicBlocks != NULL);

		char messageBuffer[64];
		for (uint32_t i = 0; i < basicBlocks->size(); i++) {
			BasicBlock* currentBasicBlock = basicBlocks->get(i);
			TessaInstruction* lastInstruction = currentBasicBlock->getLastInstruction();

			VMPI_snprintf(messageBuffer, sizeof(messageBuffer), "BB %d does not have terminator instruction\n", currentBasicBlock->getBasicBlockId());
			TessaAssertMessage(lastInstruction->isBlockTerminator(), messageBuffer);
			if (!lastInstruction->isBlockTerminator()) {
				printf("%s\n", messageBuffer);
			}
		}
	}
Exemple #11
0
void *AVMPI_allocateCodeMemory(size_t nbytes)
{
    MMgc::GCHeap* heap = MMgc::GCHeap::GetGCHeap();
    size_t pagesize = VMPI_getVMPageSize();
    
    if (nbytes % pagesize != 0) {
#ifdef DEBUG
        char buf[256];
        VMPI_snprintf(buf,
                      sizeof(buf),
                      "AVMPI_allocateCodeMemory invariants violated: request=%lu pagesize=%lu\nAborting.\n",
                      (unsigned long)nbytes,
                      (unsigned long)pagesize);
        VMPI_log(buf);
#endif
        VMPI_abort();
    }
    
    size_t nblocks = nbytes / MMgc::GCHeap::kBlockSize;
    heap->SignalCodeMemoryAllocation(nblocks, true);
    return heap->Alloc(nblocks, MMgc::GCHeap::flags_Alloc, pagesize/MMgc::GCHeap::kBlockSize);
}
Exemple #12
0
	void ConsistencyChecker::checkAllBlocksHaveOneTerminator() {
		List<BasicBlock*, LIST_GCObjects>* basicBlocks = _functionToCheck->getBasicBlocksInReversePostOrder();
		TessaAssert(basicBlocks != NULL);
		char messageBuffer[64];
		for (uint32_t i = 0; i < basicBlocks->size(); i++) {
			BasicBlock* currentBasicBlock = basicBlocks->get(i);
			List<TessaInstruction*, LIST_GCObjects>* instructions = currentBasicBlock->getInstructions();
			int numberOfTerminators = 0;

			for (uint32_t j = 0; j < instructions->size(); j++) {
				if (instructions->get(j)->isBlockTerminator()) {
					numberOfTerminators++;
				}
			}

			VMPI_snprintf(messageBuffer, sizeof(messageBuffer), "BB %d has %d terminators instruction\n", currentBasicBlock->getBasicBlockId(), numberOfTerminators);
			TessaAssertMessage(numberOfTerminators == 1, messageBuffer);
			if (numberOfTerminators != 1) {
				printf("%s\n", messageBuffer);
			}
		}
	}
Exemple #13
0
void AVMPI_makeCodeMemoryExecutable(void *address, size_t nbytes, bool makeItSo)
{
    size_t pagesize = VMPI_getVMPageSize();
    
    if ((uintptr_t)address % pagesize != 0 || nbytes % pagesize != 0) {
#ifdef DEBUG
        char buf[256];
        VMPI_snprintf(buf,
                      sizeof(buf),
                      "AVMPI_makeCodeMemoryExecutable invariants violated: address=%llu size=%llu pagesize=%llu\nAborting.\n",
                      (unsigned long long)(uintptr_t)address,
                      (unsigned long long)nbytes,
                      (unsigned long long)pagesize);
        VMPI_log(buf);
#endif
        VMPI_abort();
    }
    
    DWORD oldProtectFlags = 0;
    DWORD newProtectFlags = 0;
    if ( makeItSo )
        newProtectFlags = PAGE_EXECUTE_READ;
    else
        newProtectFlags = PAGE_READWRITE;
    
    BOOL retval;
    do {
        MEMORY_BASIC_INFORMATION mbi;
        VirtualQuery(address, &mbi, sizeof(MEMORY_BASIC_INFORMATION));
        size_t markSize = nbytes > mbi.RegionSize ? mbi.RegionSize : nbytes;  // handle multiple adjoining regions
        
        retval = VirtualProtect(address, markSize, newProtectFlags, &oldProtectFlags);
        AvmAssert(retval != 0);
        
        address = (char*) address + markSize;
        nbytes -= markSize;
    } while(nbytes != 0 && retval != 0);
}
Exemple #14
0
void AVMPI_makeCodeMemoryExecutable(void *address, size_t nbytes, bool makeItSo)
{
    size_t pagesize = VMPI_getVMPageSize();
    
    if ((uintptr_t)address % pagesize != 0 || nbytes % pagesize != 0) {
#ifdef DEBUG
        char buf[256];
        VMPI_snprintf(buf,
                      sizeof(buf),
                      "AVMPI_makeCodeMemoryExecutable invariants violated: address=%lu size=%lu pagesize=%lu\nAborting.\n",
                      (unsigned long)address,
                      (unsigned long)nbytes,
                      (unsigned long)pagesize);
        VMPI_log(buf);
#endif
        VMPI_abort();
    }
    
    int flags = makeItSo ? PROT_EXEC|PROT_READ : PROT_WRITE|PROT_READ;
    int retval = mprotect((maddr_ptr)address, (unsigned int)nbytes, flags);
    AvmAssert(retval == 0);
    (void)retval;
}
Exemple #15
0
void AVMPI_freeCodeMemory(void* address, size_t nbytes)
{
    MMgc::GCHeap* heap = MMgc::GCHeap::GetGCHeap();
    size_t pagesize = VMPI_getVMPageSize();
    size_t nblocks = heap->Size(address);
    size_t actualBytes = nblocks * MMgc::GCHeap::kBlockSize;

    if ((uintptr_t)address % pagesize != 0 || nbytes % pagesize != 0 || nbytes != actualBytes) {
#ifdef DEBUG
        char buf[256];
        VMPI_snprintf(buf,
                      sizeof(buf),
                      "AVMPI_freeCodeMemory invariants violated: address=%lu provided=%lu actual=%lu\nAborting.\n",
                      (unsigned long)address,
                      (unsigned long)nbytes,
                      (unsigned long)actualBytes);
        VMPI_log(buf);
#endif
        VMPI_abort();
    }

    heap->Free(address);
    heap->SignalCodeMemoryDeallocated(nblocks, true);
}
Exemple #16
0
	void NextNameInstruction::print() {
		char buffer[128];
		VMPI_snprintf(buffer, sizeof(buffer), "%s NextName %s.%s", getPrintPrefix().c_str(),
			receiverObject->getOperandString().c_str(), registerFile->getOperandString().c_str());
		printf("%s\n", buffer);
	}
Exemple #17
0
	void PushScopeInstruction::print() {
		char buffer[128];
		VMPI_snprintf(buffer, sizeof(buffer), "%s PushScope %s", this->getPrintPrefix().c_str(),
			this->_scopeObject->getOperandString().c_str());
		printf("%s\n", buffer);
	}