Fixes for allocation/deallocation in runtime and benchmarks (#3649)

This commit is contained in:
LepilkinaElena
2019-12-09 19:41:49 +03:00
committed by GitHub
parent 65f8a7bbf2
commit a6e1af87a4
3 changed files with 10 additions and 16 deletions
@@ -53,8 +53,9 @@ actual class StringBenchmark actual constructor() {
val result = StringBuilder()
for (i in 1..benchmarkSize) {
val pointer = findSuitableString(strings.toCStringArray(this), benchmarkSize, "a")
result.append(pointer?.toKString())
nativeHeap.free(pointer.rawValue)
val str = pointer?.toKString()
result.append(str)
freeSuitableString(pointer)
}
}
}
@@ -26,6 +26,10 @@ const char* findSuitableString(const char* stringsArray[], int arraySize, const
return NULL;
}
void freeSuitableString(char* unusedString) {
free(unusedString);
}
unsigned long int sum(int array[], int arraySize) {
unsigned long int result = 0;
for(int i = 0; i < arraySize; ++i) {
+3 -14
View File
@@ -46,19 +46,6 @@
namespace {
// TODO: it seems to be very common case; does C++ std library provide something like this?
class AutoFree {
private:
void* mem_;
public:
AutoFree(void* mem): mem_(mem) {}
~AutoFree() {
konan::free(mem_);
}
};
// RuntimeUtils.kt
extern "C" void ReportUnhandledException(KRef throwable);
extern "C" void ExceptionReporterLaunchpad(KRef reporter, KRef throwable);
@@ -182,7 +169,7 @@ OBJ_GETTER(GetStackTraceStrings, KConstRef stackTrace) {
if (size > 0) {
char **symbols = backtrace_symbols(PrimitiveArrayAddressOfElementAt<KNativePtr>(stackTrace->array(), 0), size);
RuntimeCheck(symbols != nullptr, "Not enough memory to retrieve the stacktrace");
AutoFree autoFree(symbols);
for (int index = 0; index < size; ++index) {
auto sourceInfo = Kotlin_getSourceInfo(*PrimitiveArrayAddressOfElementAt<KNativePtr>(stackTrace->array(), index));
const char* symbol = symbols[index];
@@ -203,6 +190,8 @@ OBJ_GETTER(GetStackTraceStrings, KConstRef stackTrace) {
CreateStringFromCString(result, holder.slot());
UpdateHeapRef(ArrayAddressOfElementAt(strings->array(), index), holder.obj());
}
// Not konan::free. Used to free memory allocated in backtrace_symbols where malloc is used.
free(symbols);
}
#endif
RETURN_OBJ(strings);