示例#1
0
    void test_writeBarrier_2(void)
    {
        GC::initialize();

        Bytecode* myBytecode = gCodeManager.readBytecode("test.hyb");
        myBytecode->setInitialized();

        Context* context = gCodeManager.createContext();
        Thread* pThread = gThreadManager.createTmpThread();
        context->pushClass(myBytecode->mainClass());
        context->methodCall(HSym_gc_test_writeBarrier_2, 0);
        pThread->initialize(context);
        pThread->start();

        GC::unmark();
        while (gThreadManager.isThreadRunning()) {
            gThreadManager.exec1tick();
            GC::incremental();
        }

        GC::full();
        Value* ga = gGlobalVar.getVarAddr_notCreate(HSym_a);
        CPPUNIT_ASSERT(ga != NULL);
        ValueArray* arr = ga->toCppObj<ValueArray>(HSym_Array);
        for (int i = 0; i < 50; ++i) {
            Value v = arr->nth(i);
            Object* obj = v.toObj();
            CPPUNIT_ASSERT_EQUAL(HC_Array, obj->type());
            CPPUNIT_ASSERT(obj->isMarked());
            ValueArray* a2 = obj->cppObj<ValueArray>();
            obj = a2->nth(0).toObj();
            CPPUNIT_ASSERT_EQUAL(HC_StringBuffer, obj->type());
            CPPUNIT_ASSERT(obj->isMarked());
            obj = a2->nth(1).toObj();
            CPPUNIT_ASSERT_EQUAL(HC_StringBuffer, obj->type());
            CPPUNIT_ASSERT(obj->isMarked());
        }

        GC::finalize();
    }
示例#2
0
    void test_writeBarrier(void)
    {
        GC::initialize();

        Bytecode* myBytecode = gCodeManager.readBytecode("test.hyb");
        myBytecode->setInitialized();

        Context* context = gCodeManager.createContext();
        Thread* pThread = gThreadManager.createTmpThread();
        context->pushClass(myBytecode->mainClass());
        context->methodCall(HSym_gc_test_writeBarrier, 0);
        pThread->initialize(context);
        pThread->start();

        gThreadManager.exec1tick();
        GC::unmark();

        for (int i = 0; i < 300; ++i) {
            gThreadManager.exec1tick();
            GC::incremental();
        }

        GC::full();
        Value* ga = gGlobalVar.getVarAddr_notCreate(HSym_a);
        CPPUNIT_ASSERT(ga != NULL);
        ValueArray* arr = ga->toCppObj<ValueArray>(HSym_Array);
        for (int i = 0; i < 100; ++i) {
            Value v = arr->nth(i);
            Object* obj = v.toObj();
            CPPUNIT_ASSERT_EQUAL(HC_StringBuffer, obj->type());
            //StringBuffer* sb = obj->cppObj<StringBuffer>();
            //HMD_PRINTF("%d:%x %x type=%x(SB=%x)",i,obj,sb,obj->type(),HC_StringBuffer);
            //HMD_PRINTF(" bufSize=%d,length=%d,buf=%x\n",sb->bufSize(),sb->length(),sb->top());
            CPPUNIT_ASSERT(obj->isMarked());
        }

        GC::finalize();
    }