pair<BytesShared, size_t> PaymentOperationStateHandler::byTransaction( const TransactionUUID &transactionUUID) { string query = "SELECT state, state_bytes_count FROM " + mTableName + " WHERE transaction_uuid = ?;"; sqlite3_stmt *stmt; int rc = sqlite3_prepare_v2(mDataBase, query.c_str(), -1, &stmt, 0); if (rc != SQLITE_OK) { throw IOError("PaymentOperationStateHandler::byTransaction: " "Bad query; sqlite error: " + to_string(rc)); } rc = sqlite3_bind_blob(stmt, 1, transactionUUID.data, NodeUUID::kBytesSize, SQLITE_STATIC); if (rc != SQLITE_OK) { throw IOError("PaymentOperationStateHandler::byTransaction: " "Bad binding of TransactionUUID; sqlite error: " + to_string(rc)); } rc = sqlite3_step(stmt); if (rc == SQLITE_ROW) { size_t stateBytesCount = (size_t)sqlite3_column_int(stmt, 1); BytesShared state = tryMalloc(stateBytesCount); memcpy( state.get(), sqlite3_column_blob(stmt, 0), stateBytesCount); sqlite3_reset(stmt); sqlite3_finalize(stmt); return make_pair(state, stateBytesCount); } else { sqlite3_reset(stmt); sqlite3_finalize(stmt); throw NotFoundError("PaymentOperationStateHandler::byTransaction: " "There are now records with requested transactionUUID"); } }
/* * Allocate storage on the GC heap. We guarantee 8-byte alignment. * * The new storage is zeroed out. * * Note that, in rare cases, this could get called while a GC is in * progress. If a non-VM thread tries to attach itself through JNI, * it will need to allocate some objects. If this becomes annoying to * deal with, we can block it at the source, but holding the allocation * mutex should be enough. * * In rare circumstances (JNI AttachCurrentThread) we can be called * from a non-VM thread. * * Use ALLOC_DONT_TRACK when we either don't want to track an allocation * (because it's being done for the interpreter "new" operation and will * be part of the root set immediately) or we can't (because this allocation * is for a brand new thread). * * Returns NULL and throws an exception on failure. * * TODO: don't do a GC if the debugger thinks all threads are suspended */ void* dvmMalloc(size_t size, int flags) { void *ptr; dvmLockHeap(); /* Try as hard as possible to allocate some memory. */ ptr = tryMalloc(size); if (ptr != NULL) { /* We've got the memory. */ if (gDvm.allocProf.enabled) { Thread* self = dvmThreadSelf(); gDvm.allocProf.allocCount++; gDvm.allocProf.allocSize += size; if (self != NULL) { self->allocProf.allocCount++; self->allocProf.allocSize += size; } } } else { /* The allocation failed. */ if (gDvm.allocProf.enabled) { Thread* self = dvmThreadSelf(); gDvm.allocProf.failedAllocCount++; gDvm.allocProf.failedAllocSize += size; if (self != NULL) { self->allocProf.failedAllocCount++; self->allocProf.failedAllocSize += size; } } } dvmUnlockHeap(); if (ptr != NULL) { /* * If caller hasn't asked us not to track it, add it to the * internal tracking list. */ if ((flags & ALLOC_DONT_TRACK) == 0) { dvmAddTrackedAlloc((Object*)ptr, NULL); } } else { /* * The allocation failed; throw an OutOfMemoryError. */ throwOOME(); } return ptr; }
void* fastiva_dvmMalloc(size_t size, int flags, ClassObject* clazz) { #endif void *ptr; dvmLockHeap(); /* Try as hard as possible to allocate some memory. */ ptr = tryMalloc(size); if (ptr != NULL) { /* We've got the memory. */ if (gDvm.allocProf.enabled) { Thread* self = dvmThreadSelf(); gDvm.allocProf.allocCount++; gDvm.allocProf.allocSize += size; if (self != NULL) { self->allocProf.allocCount++; self->allocProf.allocSize += size; } } } else { /* The allocation failed. */ if (gDvm.allocProf.enabled) { Thread* self = dvmThreadSelf(); gDvm.allocProf.failedAllocCount++; gDvm.allocProf.failedAllocSize += size; if (self != NULL) { self->allocProf.failedAllocCount++; self->allocProf.failedAllocSize += size; } } } #ifdef FASTIVA if (clazz != NULL && ptr != NULL) { // for suspend-by-signal it must be in HeapLocked scope. DVM_OBJECT_INIT((Object*)ptr, clazz); d2f_initObject((Object*)ptr, clazz); } #endif dvmUnlockHeap(); if (ptr != NULL) { /* * If caller hasn't asked us not to track it, add it to the * internal tracking list. */ if ((flags & ALLOC_DONT_TRACK) == 0) { dvmAddTrackedAlloc((Object*)ptr, NULL); } } else { /* * The allocation failed; throw an OutOfMemoryError. */ throwOOME(); } return ptr; }