size_t getFolderSize(const std::string& path)
{
    size_t size = 0;

    DIR *dir;
    std::vector<std::string> localDirs;
    if ((dir=opendir(path.c_str())) == NULL) {
        LogError("Cannot open dir " << path);
        return 0;
    }
    struct dirent* el;
    while ((el = readdir(dir)) != 0) {
        if (strcmp(el->d_name, ".") == 0 || strcmp(el->d_name, "..") == 0) {
            continue;
        }
        struct stat tmp;
        std::string local = path + el->d_name;
        if (stat(local.c_str(), &tmp) == -1) {
            LogError("Failed to open file " << local);
            char* errstring = strerror(errno);
            LogError("Reason: " << errstring);
            continue;
        }

        size += getObjectSize(local);
        if (S_ISDIR(tmp.st_mode)) {
            localDirs.push_back(local + "/");
        }
    }

    closedir(dir);

    FOREACH (localDir, localDirs) {
        size += getFolderSize(*localDir);
    }
void delete_Continuation(ObjectData* od, const Class*) {
  auto const cont = static_cast<c_Continuation*>(od);
  auto const size = cont->getObjectSize();
  cont->~c_Continuation();
  if (LIKELY(size <= kMaxSmartSize)) {
    return MM().smartFreeSizeLogged(cont, size);
  }
  MM().smartFreeSizeBigLogged(cont, size);
}
void traverseAndWriteNode(struct node_t* node) {
    if (node == NULL) //not needed?
        return;
    printf("Node name = %s, type=%d\n", node->name, node->type);
    writeCommonPart(node);
    switch (node->type) {
        case RBRANCH:
        {
            rbranch_node_t* node2 = (rbranch_node_t*)node;
            fwrite(&(node2->childTypeLen), sizeof(int), 1, treeFp);
            fwrite(&(node2->numOfProperties), sizeof(int), 1, treeFp);
            if (node2->numOfProperties > 0) {
                fwrite(node2->propertyDefinition, sizeof(propertyDefinition_t)*node2->numOfProperties, 1, treeFp);
            }
        }
        break;
        case ELEMENT:
        {
            element_node_t* node2 = (element_node_t*)node;
            int objectType = ((resourceObject_t*)node2->uniqueObject)->objectType;
            int objectSize = getObjectSize(objectType);
            if (objectSize > 0) {
                fwrite(node2->uniqueObject, objectSize, 1, treeFp);
                writeUniqueObjectRefs(objectType, node2->uniqueObject);
            }
        }
        break;
        default:
        {
            fwrite(&(node->datatype), sizeof(int), 1, treeFp);
            fwrite(&(node->min), sizeof(int), 1, treeFp);
            fwrite(&(node->max), sizeof(int), 1, treeFp);
            fwrite(&(node->unitLen), sizeof(int), 1, treeFp);
            if (node->unitLen > 0)
                fwrite(node->unit, sizeof(char)*node->unitLen, 1, treeFp);
            fwrite(&(node->numOfEnumElements), sizeof(int), 1, treeFp);
            if (node->numOfEnumElements > 0) {
                fwrite(node->enumeration, sizeof(enum_t)*node->numOfEnumElements, 1, treeFp);
            }
            fwrite(&(node->functionLen), sizeof(int), 1, treeFp);
            if (node->functionLen > 0)
                fwrite(node->function, sizeof(char)*node->functionLen, 1, treeFp);
//printf("numOfEnumElements=%d, unitlen=%d, functionLen=%d\n", node->numOfEnumElements, node->unitLen, node->functionLen);
for (int i = 0 ; i < node->numOfEnumElements ; i++)
  printf("Enum[%d]=%s\n", i, (char*)node->enumeration[i]);
        }
        break;
    } //switch
    int childNo = 0;
printf("node->children = %d\n", node->children);
    while(childNo < node->children) {
         traverseAndWriteNode(node->child[childNo++]);
    }
}
Example #4
0
/*
 * Class:     sun_instrument_InstrumentationImpl
 * Method:    getObjectSize0
 * Signature: (Ljava/lang/Object;)J
 */
JNIEXPORT jlong JNICALL Java_sun_instrument_InstrumentationImpl_getObjectSize0
  (JNIEnv * jnienv, jobject implThis, jobject objectToSize) {
    jlong           result = 0;
    JPLISAgent *    agent = getJPLISAgentFromJavaImpl(jnienv, implThis);
    if ( agent == NULL ) {
        createAndThrowInternalError(jnienv);
    }
    else {
        result = getObjectSize(jnienv, agent, objectToSize);
    }
    return result;
}
Example #5
0
 inline size_t getObjectDataSize() { return getObjectSize() - getObjectHeaderSize(); }
void TestObjectRecognition() {
    size_t headersSize = sizeof(LargeMemoryBlock)+sizeof(LargeObjectHdr);
    unsigned falseObjectSize = 113; // unsigned is the type expected by getObjectSize
    size_t obtainedSize;

    ASSERT(sizeof(BackRefIdx)==4, "Unexpected size of BackRefIdx");
    ASSERT(getObjectSize(falseObjectSize)!=falseObjectSize, "Error in test: bad choice for false object size");

    void* mem = scalable_malloc(2*slabSize);
    ASSERT(mem, "Memory was not allocated");
    Block* falseBlock = (Block*)alignUp((uintptr_t)mem, slabSize);
    falseBlock->objectSize = falseObjectSize;
    char* falseSO = (char*)falseBlock + falseObjectSize*7;
    ASSERT(alignDown(falseSO, slabSize)==(void*)falseBlock, "Error in test: false object offset is too big");

    void* bufferLOH = scalable_malloc(2*slabSize + headersSize);
    ASSERT(bufferLOH, "Memory was not allocated");
    LargeObjectHdr* falseLO = 
        (LargeObjectHdr*)alignUp((uintptr_t)bufferLOH + headersSize, slabSize);
    LargeObjectHdr* headerLO = (LargeObjectHdr*)falseLO-1;
    headerLO->memoryBlock = (LargeMemoryBlock*)bufferLOH;
    headerLO->memoryBlock->unalignedSize = 2*slabSize + headersSize;
    headerLO->memoryBlock->objectSize = slabSize + headersSize;
    headerLO->backRefIdx = BackRefIdx::newBackRef(/*largeObj=*/true);
    setBackRef(headerLO->backRefIdx, headerLO);
    ASSERT(scalable_msize(falseLO) == slabSize + headersSize,
           "Error in test: LOH falsification failed");
    removeBackRef(headerLO->backRefIdx);

    const int NUM_OF_IDX = BR_MAX_CNT+2;
    BackRefIdx idxs[NUM_OF_IDX];
    for (int cnt=0; cnt<2; cnt++) {
        for (int master = -10; master<10; master++) {
            falseBlock->backRefIdx.master = (uint16_t)master;
            headerLO->backRefIdx.master = (uint16_t)master;
        
            for (int bl = -10; bl<BR_MAX_CNT+10; bl++) {
                falseBlock->backRefIdx.offset = (uint16_t)bl;
                headerLO->backRefIdx.offset = (uint16_t)bl;

                for (int largeObj = 0; largeObj<2; largeObj++) {
                    falseBlock->backRefIdx.largeObj = largeObj;
                    headerLO->backRefIdx.largeObj = largeObj;

                    obtainedSize = safer_scalable_msize(falseSO, NULL);
                    ASSERT(obtainedSize==0, "Incorrect pointer accepted");
                    obtainedSize = safer_scalable_msize(falseLO, NULL);
                    ASSERT(obtainedSize==0, "Incorrect pointer accepted");
                }
            }
        }
        if (cnt == 1) {
            for (int i=0; i<NUM_OF_IDX; i++)
                removeBackRef(idxs[i]);
            break;
        }
        for (int i=0; i<NUM_OF_IDX; i++) {
            idxs[i] = BackRefIdx::newBackRef(/*largeObj=*/false);
            setBackRef(idxs[i], NULL);
        }
    }
    char *smallPtr = (char*)scalable_malloc(falseObjectSize);
    obtainedSize = safer_scalable_msize(smallPtr, NULL);
    ASSERT(obtainedSize==getObjectSize(falseObjectSize), "Correct pointer not accepted?");
    scalable_free(smallPtr);

    obtainedSize = safer_scalable_msize(mem, NULL);
    ASSERT(obtainedSize>=2*slabSize, "Correct pointer not accepted?");
    scalable_free(mem);
    scalable_free(bufferLOH);
}
/*
  Data order on file: 
  - Common part
  - Name
  - Description
  if (node_t)
    - node_t specific
	* min/max/unit/enum
  if (rbranch_node_t)
    - rbranch specific
	* childType/numOfProperties/Properties
  if (element_node_t)
    - specific according to parent child type (mapped to struct def)
*/
struct node_t* traverseAndReadNode(struct node_t* parentPtr) {
if (parentPtr != NULL)
  printf("parent node name = %s\n", parentPtr->name);
    common_node_data_t* common_data = (common_node_data_t*)malloc(sizeof(common_node_data_t));
    if (common_data == NULL) {
        printf("traverseAndReadNode: 1st malloc failed\n");
        return NULL;
    }
    updateTreeDepth(1);
    char* name;
    char* descr;
    readCommonPart(common_data, &name, &descr);
    node_t* node = NULL;
printf("Type=%d\n",common_data->type);
    switch (common_data->type) {
        case RBRANCH:
        {
            rbranch_node_t* node2 = (rbranch_node_t*) malloc(sizeof(rbranch_node_t));
            node2->parent = parentPtr;
            copyData((node_t*)node2, common_data, name, descr);
            if (common_data->children > 0)
                node2->child = (element_node_t**) malloc(sizeof(element_node_t**)*common_data->children);
            fread(&(node2->childTypeLen), sizeof(int), 1, treeFp);
            fread(&(node2->numOfProperties), sizeof(int), 1, treeFp);
            if (node2->numOfProperties > 0) {
                node2->propertyDefinition = (propertyDefinition_t*) malloc(sizeof(propertyDefinition_t)*node2->numOfProperties);
                fread(node2->propertyDefinition, sizeof(propertyDefinition_t)*node2->numOfProperties, 1, treeFp);
            }
            node = (node_t*)node2;
        }
        break;
        case ELEMENT:
        {
            element_node_t* node2 = (element_node_t*) malloc(sizeof(element_node_t));
            node2->parent = parentPtr;
            copyData((node_t*)node2, common_data, name, descr);
            objectTypes_t objectType;
            fread(&objectType, sizeof(int), 1, treeFp);
            int objectSize = getObjectSize(objectType);
            if (objectSize > 0) {
                node2->uniqueObject = (void*) malloc(objectSize);
                *((int*)node2->uniqueObject) = objectType;
                fread(node2->uniqueObject+sizeof(int), objectSize-sizeof(int), 1, treeFp);
                readUniqueObjectRefs(objectType, node2->uniqueObject);
            }
            node = (node_t*)node2;
        }
        break;
        default:
        {
            node_t* node2 = (node_t*) malloc(sizeof(node_t));
            node2->parent = parentPtr;
            copyData((node_t*)node2, common_data, name, descr);
            if (node2->children > 0)
                node2->child = (node_t**) malloc(sizeof(node_t**)*node2->children);
            fread(&(node2->datatype), sizeof(int), 1, treeFp);
            fread(&(node2->min), sizeof(int), 1, treeFp);
            fread(&(node2->max), sizeof(int), 1, treeFp);
            fread(&(node2->unitLen), sizeof(int), 1, treeFp);
            node2->unit = NULL;
            if (node2->unitLen > 0) {
                node2->unit = (char*) malloc(sizeof(char)*(node2->unitLen+1));
                fread(node2->unit, sizeof(char)*node2->unitLen, 1, treeFp);
                node2->unit[node2->unitLen] = '\0';
            }
if (node2->unitLen > 0)
    printf("Unit = %s\n", node2->unit);
            fread(&(node2->numOfEnumElements), sizeof(int), 1, treeFp);
            if (node2->numOfEnumElements > 0) {
                node2->enumeration = (enum_t*) malloc(sizeof(enum_t)*node2->numOfEnumElements);
                fread(node2->enumeration, sizeof(enum_t)*node2->numOfEnumElements, 1, treeFp);
            }
for (int i = 0 ; i < node2->numOfEnumElements ; i++)
  printf("Enum[%d]=%s\n", i, (char*)node2->enumeration[i]);
            fread(&(node2->functionLen), sizeof(int), 1, treeFp);
            node2->function = NULL;
            if (node2->functionLen > 0) {
                node2->function = (char*) malloc(sizeof(char)*(node2->functionLen+1));
                fread(node2->function, sizeof(char)*node2->functionLen, 1, treeFp);
                node2->function[node2->functionLen] = '\0';
            }
if (node2->functionLen > 0)
    printf("Function = %s\n", node2->function);
            node = (node_t*)node2;
        }
        break;
    } //switch
    free(common_data);
    free(name);
    free(descr);
printf("node->children = %d\n", node->children);
    int childNo = 0;
    while(childNo < node->children) {
        node->child[childNo++] = traverseAndReadNode(node);
    }
    updateTreeDepth(-1);
    return node;
}
Example #8
0
/*
 * Class:     sun_instrument_InstrumentationImpl
 * Method:    getObjectSize0
 * Signature: (Ljava/lang/Object;)J
 */
JNIEXPORT jlong JNICALL Java_sun_instrument_InstrumentationImpl_getObjectSize0
  (JNIEnv * jnienv, jobject implThis, jlong agent, jobject objectToSize) {
    return getObjectSize(jnienv, (JPLISAgent*)agent, objectToSize);
}