Example #1
0
 size_t getAllocatedBytes() const
 {
     if (!isReady()) return 0;
     size_t bytes = memoryManager().allocated(data.get());
     // External device poitner
     if (bytes == 0 && data.get()) {
         return data_dims.elements() * sizeof(T);
     }
     return  bytes;
 }
Example #2
0
	// Entry point from the normal count down mechanism - not used from GC as that queues many objects
	// which could generate a large number of async. signals to the same semaphore
	void ObjectMemory::finalize(OTE* ote)
	{
		#if defined(_DEBUG)
		{
			if (abs(Interpreter::executionTrace) > 1)
			{
				tracelock lock(TRACESTREAM);
				TRACESTREAM << "Finalizing " << ote << "\n";
			}
		}
		#endif
		
		MemoryManager* memMan = memoryManager();
		Interpreter::queueForFinalization(ote, (unsigned)integerValueOf(memMan->m_hospiceHighWater));
	}
Example #3
0
File: main.cpp Project: 0x7CFE/llst
int main(int argc, char **argv) {
    args llstArgs;

    llstArgs.heapSize = 1048576;
    llstArgs.maxHeapSize = 1048576 * 100;
    llstArgs.imagePath = "../image/LittleSmalltalk.image";

    llstArgs.parse(argc, argv);

    if (llstArgs.showHelp) {
        std::cout << args::getHelp() << std::endl;
        return EXIT_SUCCESS;
    }

    if (llstArgs.showVersion) {
        std::cout << args::getVersion() << std::endl;
        return EXIT_SUCCESS;
    }

    IMemoryManager* mm;
    if(llstArgs.memoryManagerType == "nc") {
        mm = new NonCollectMemoryManager();
    }
    else if(llstArgs.memoryManagerType == "" || llstArgs.memoryManagerType == "copy") {
        #if defined(LLVM)
            mm = new LLVMMemoryManager();
        #else
            mm = new BakerMemoryManager();
        #endif
    }
    else{
        std::cout << "error: wrong option --mm_type=" << llstArgs.memoryManagerType << ";\n"
                  << "defined options for memory manager type:\n"
                  << "\"copy\" (default) - copying garbage collector;\n"
                  << "\"nc\" - non-collecting memory manager.\n";
        return EXIT_FAILURE;
    }
    std::auto_ptr<IMemoryManager> memoryManager(mm);
    memoryManager->initializeHeap(llstArgs.heapSize, llstArgs.maxHeapSize);
    memoryManager->setLogger(std::tr1::shared_ptr<IGCLogger>(new GCLogger("gc.log")));
    std::auto_ptr<Image> smalltalkImage(new Image(memoryManager.get()));
    smalltalkImage->loadImage(llstArgs.imagePath);

    SmalltalkVM vm(smalltalkImage.get(), memoryManager.get());

    // Creating completion database and filling it with info
    CompletionEngine* completionEngine = CompletionEngine::Instance();
    completionEngine->initialize(globals.globalsObject);
    completionEngine->addWord("Smalltalk");

#if defined(LLVM)
    JITRuntime runtime;
    runtime.initialize(&vm);
#endif

    // Creating runtime context
    hptr<TContext> initContext = vm.newObject<TContext>();
    hptr<TProcess> initProcess = vm.newObject<TProcess>();
    initProcess->context = initContext;

    initContext->arguments = vm.newObject<TObjectArray>(1);
    initContext->arguments->putField(0, globals.nilObject);

    initContext->bytePointer = 0;
    initContext->previousContext = static_cast<TContext*>(globals.nilObject);

    const uint32_t stackSize = globals.initialMethod->stackSize;
    initContext->stack = vm.newObject<TObjectArray>(stackSize);
    initContext->stackTop = 0;

    initContext->method = globals.initialMethod;

    // FIXME image builder does not calculate temporary size
    //uint32_t tempsSize = getIntegerValue(initContext->method->temporarySize);
    initContext->temporaries = vm.newObject<TObjectArray>(42);

    // And starting the image execution!
    SmalltalkVM::TExecuteResult result = vm.execute(initProcess, 0);

    /* This code will run Smalltalk immediately in LLVM.
     * Don't forget to uncomment 'Undefined>>boot'
     */
    /*
    typedef int32_t (*TExecuteProcessFunction)(TProcess*);
    TExecuteProcessFunction executeProcess = reinterpret_cast<TExecuteProcessFunction>(runtime.getExecutionEngine()->getPointerToFunction(runtime.getModule()->getFunction("executeProcess")));
    SmalltalkVM::TExecuteResult result = (SmalltalkVM::TExecuteResult) executeProcess(initProcess);
    */

    // Finally, parsing the result
    switch (result) {
        case SmalltalkVM::returnError:
            std::printf("User defined return\n");
            break;

        case SmalltalkVM::returnBadMethod:
            std::printf("Could not lookup method\n");
            break;

        case SmalltalkVM::returnReturned:
            // normal return
            std::printf("Exited normally\n");
            break;

        case SmalltalkVM::returnTimeExpired:
            std::printf("Execution time expired\n");
            break;

        default:
            std::printf("Unknown return code: %d\n", result);

    }

    TMemoryManagerInfo info = memoryManager->getStat();

    int averageAllocs = info.collectionsCount ? info.allocationsCount / info.collectionsCount : info.allocationsCount;
    std::printf("\nGC count: %d (%d/%d), average allocations per gc: %d, microseconds spent in GC: %d\n",
           info.collectionsCount, info.leftToRightCollections, info.rightToLeftCollections, averageAllocs, static_cast<uint32_t>(info.totalCollectionDelay));

    vm.printVMStat();

#if defined(LLVM)
    runtime.printStat();
#endif

    return EXIT_SUCCESS;
}
Example #4
0
void Inequality<T, Set>::operator delete(void* pointer)
{
   memoryManager().deleteCell(pointer);
}
Example #5
0
void* Inequality<T, Set>::operator new(size_t size)
{
    return memoryManager().newCell();
}