int zeroLengthByteArraySize = (int) whiteBox.getObjectSize(newbyte[0]);
// Since we do not know is there any padding in zeroLengthByteArraySize we cannot just take byte[0] size as overhead for (int i = 1; i < MAX_PADDING_SIZE + 1; ++i) { int realAllocationSize = (int) whiteBox.getObjectSize(newbyte[i]); if (realAllocationSize != zeroLengthByteArraySize) { // It means we did not have any padding on previous step return zeroLengthByteArraySize - (i - 1);
}
} thrownew Error("We cannot find byte[] memory overhead - should not reach here");
}
if (instanceSize % SIZE_OF_LONG != 0L) { thrownew Error(String.format("Test bug: only sizes aligned by %d bytes are supported and %d was specified",
SIZE_OF_LONG, instanceSize));
}
int instanceSizeWithoutObjectHeaderInWords =
(int) (instanceSize - WhiteBox.getWhiteBox().getObjectSize(new Object())) / SIZE_OF_LONG;
if (instanceSizeWithoutObjectHeaderInWords <= 0) { thrownew Error(String.format("Test bug: specified instance size is too small - %d."
+ " Cannot generate any classes", instanceSize));
}
int sizeOfLastFile = instanceSizeWithoutObjectHeaderInWords % MAXIMUM_AMOUNT_OF_FIELDS_IN_CLASS; int generatedClassesCount = instanceSizeWithoutObjectHeaderInWords / MAXIMUM_AMOUNT_OF_FIELDS_IN_CLASS;
// Do all the classes have the maximum number of fields? int fieldsInLastClassCount;
// first (generatedClassesCount - 1) classes are just fillers - just long fields and constructor for (int i = 0; i < generatedClassesCount - 1; i++) {
String clsName = prefix + i;
Helpers.compileClass(clsName, workDir,
Helpers.generate(
clsName, // first generated class extends base class
(i == 0 ? baseClass : prefix + (i - 1)),
constructorTemplate.replace("${ClassName}", clsName),
MAXIMUM_AMOUNT_OF_FIELDS_IN_CLASS));
}
// generating last class - the one with specified className
Helpers.compileClass(className, workDir,
classTemplate.replaceAll("\\$\\{ClassName\\}", className) // if no fillers were generated (generatedClassesCount == 1) // the last class should extends baseClass // otherwise it should extend last generated filler class which name is // prefix + (generatedClassesCount - 2) // generatedClassesCount is always not smaller than 1
.replace("${BaseClass}",
generatedClassesCount == 1 ? baseClass :
prefix + (generatedClassesCount - 2))
.replace("${Fields}", fieldsGenerator(fieldsInLastClassCount))
);
}
/** *WaitsuntilConcurentMarkCyclefinishes * *@paramwbWhiteboxinstance *@paramsleepTimesleeptime
*/ publicstaticvoid waitTillCMCFinished(WhiteBox wb, int sleepTime) { while (wb.g1InConcurrentMark()) { if (sleepTime > -1) { try { Thread.sleep(sleepTime);
} catch (InterruptedException e) {
System.out.println("Got InterruptedException while waiting for ConcMarkCycle to finish"); Thread.currentThread().interrupt(); break;
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.