diff options
Diffstat (limited to 'src')
32 files changed, 277 insertions, 354 deletions
diff --git a/src/class_linker.cc b/src/class_linker.cc index 47beadb4e8..f891913770 100644 --- a/src/class_linker.cc +++ b/src/class_linker.cc @@ -844,7 +844,7 @@ void ClassLinker::InitFromImage() { OatFile* oat_file = OpenOat(space); CHECK(oat_file != NULL) << "Failed to open oat file for image"; CHECK_EQ(oat_file->GetOatHeader().GetImageFileLocationChecksum(), 0U); - CHECK(oat_file->GetOatHeader().GetImageFileLocation() == ""); + CHECK(oat_file->GetOatHeader().GetImageFileLocation().empty()); Object* dex_caches_object = space->GetImageHeader().GetImageRoot(ImageHeader::kDexCaches); ObjectArray<DexCache>* dex_caches = dex_caches_object->AsObjectArray<DexCache>(); diff --git a/src/compiler/codegen/MethodBitcode.cc b/src/compiler/codegen/MethodBitcode.cc index 66823c2313..ad9b020e9e 100644 --- a/src/compiler/codegen/MethodBitcode.cc +++ b/src/compiler/codegen/MethodBitcode.cc @@ -29,7 +29,7 @@ #include <llvm/Support/Casting.h> #include <llvm/Support/InstIterator.h> -const char* labelFormat = "L0x%x_%d"; +static const char* kLabelFormat = "L0x%x_%d"; namespace art { extern const RegLocation badLoc; @@ -345,7 +345,7 @@ void setShadowFrameEntry(CompilationUnit* cUnit, llvm::Value* newVal) break; } } - DCHECK(index != -1) << "Corrupt shadowMap"; + DCHECK_NE(index, -1) << "Corrupt shadowMap"; greenland::IntrinsicHelper::IntrinsicId id = greenland::IntrinsicHelper::SetShadowFrameEntry; llvm::Function* func = cUnit->intrinsic_helper->GetIntrinsicFunction(id); @@ -1341,7 +1341,7 @@ bool createLLVMBasicBlock(CompilationUnit* cUnit, BasicBlock* bb) bool entryBlock = (bb->blockType == kEntryBlock); llvm::BasicBlock* llvmBB = llvm::BasicBlock::Create(*cUnit->context, entryBlock ? "entry" : - StringPrintf(labelFormat, offset, bb->id), + StringPrintf(kLabelFormat, offset, bb->id), cUnit->func); if (entryBlock) { cUnit->entryBB = llvmBB; @@ -1443,17 +1443,16 @@ RegLocation getLoc(CompilationUnit* cUnit, llvm::Value* val) { DCHECK(val != NULL); SafeMap<llvm::Value*, RegLocation>::iterator it = cUnit->locMap.find(val); if (it == cUnit->locMap.end()) { - const char* valName = val->getName().str().c_str(); - DCHECK(valName != NULL); - DCHECK(strlen(valName) > 0); + std::string valName(val->getName().str()); + DCHECK(!valName.empty()); if (valName[0] == 'v') { int baseSReg = INVALID_SREG; - sscanf(valName, "v%d_", &baseSReg); + sscanf(valName.c_str(), "v%d_", &baseSReg); res = cUnit->regLocation[baseSReg]; cUnit->locMap.Put(val, res); } else { UNIMPLEMENTED(WARNING) << "Need to handle llvm temps"; - DCHECK(valName[0] == 't'); + DCHECK_EQ(valName[0], 't'); } } else { res = it->second; @@ -1628,7 +1627,7 @@ void cvtCall(CompilationUnit* cUnit, llvm::CallInst* callInst, void cvtCopy(CompilationUnit* cUnit, llvm::CallInst* callInst) { - DCHECK(callInst->getNumArgOperands() == 1); + DCHECK_EQ(callInst->getNumArgOperands(), 1); RegLocation rlSrc = getLoc(cUnit, callInst->getArgOperand(0)); RegLocation rlDest = getLoc(cUnit, callInst); if (rlSrc.wide) { @@ -1641,7 +1640,7 @@ void cvtCopy(CompilationUnit* cUnit, llvm::CallInst* callInst) // Note: Immediate arg is a ConstantInt regardless of result type void cvtConst(CompilationUnit* cUnit, llvm::CallInst* callInst) { - DCHECK(callInst->getNumArgOperands() == 1); + DCHECK_EQ(callInst->getNumArgOperands(), 1); llvm::ConstantInt* src = llvm::dyn_cast<llvm::ConstantInt>(callInst->getArgOperand(0)); uint64_t immval = src->getZExtValue(); @@ -1659,7 +1658,7 @@ void cvtConst(CompilationUnit* cUnit, llvm::CallInst* callInst) void cvtConstString(CompilationUnit* cUnit, llvm::CallInst* callInst) { - DCHECK(callInst->getNumArgOperands() == 1); + DCHECK_EQ(callInst->getNumArgOperands(), 1); llvm::ConstantInt* stringIdxVal = llvm::dyn_cast<llvm::ConstantInt>(callInst->getArgOperand(0)); uint32_t stringIdx = stringIdxVal->getZExtValue(); @@ -1733,7 +1732,7 @@ bool methodBitcodeBlockCodeGen(CompilationUnit* cUnit, llvm::BasicBlock* bb) if (!isEntry) { const char* blockName = bb->getName().str().c_str(); int dummy; - sscanf(blockName, labelFormat, &blockLabel->operands[0], &dummy); + sscanf(blockName, kLabelFormat, &blockLabel->operands[0], &dummy); } // Set the label kind blockLabel->opcode = kPseudoNormalBlockLabel; diff --git a/src/compiler/codegen/MethodCodegenDriver.cc b/src/compiler/codegen/MethodCodegenDriver.cc index 7898ddb7be..a07e569394 100644 --- a/src/compiler/codegen/MethodCodegenDriver.cc +++ b/src/compiler/codegen/MethodCodegenDriver.cc @@ -1020,7 +1020,7 @@ void oatSpecialMIR2LIR(CompilationUnit* cUnit, SpecialCaseHandler specialCase) return; } DCHECK_EQ(bb->startOffset, 0); - DCHECK(bb->firstMIRInsn != 0); + DCHECK(bb->firstMIRInsn != NULL); /* Get the first instruction */ MIR* mir = bb->firstMIRInsn; diff --git a/src/compiler/codegen/Ralloc.h b/src/compiler/codegen/Ralloc.h index ec47e22963..d1518e8e3f 100644 --- a/src/compiler/codegen/Ralloc.h +++ b/src/compiler/codegen/Ralloc.h @@ -50,14 +50,12 @@ inline int oatSRegHi(int lowSreg) { } -inline bool oatLiveOut(CompilationUnit* cUnit, int sReg) -{ +inline bool oatLiveOut(CompilationUnit* cUnit, int sReg) { //For now. return true; } -inline int oatSSASrc(MIR* mir, int num) -{ +inline int oatSSASrc(MIR* mir, int num) { DCHECK_GT(mir->ssaRep->numUses, num); return mir->ssaRep->uses[num]; } diff --git a/src/compiler/codegen/RallocUtil.cc b/src/compiler/codegen/RallocUtil.cc index 074fd26ca0..affb545aea 100644 --- a/src/compiler/codegen/RallocUtil.cc +++ b/src/compiler/codegen/RallocUtil.cc @@ -1003,7 +1003,7 @@ extern RegLocation oatGetRawSrc(CompilationUnit* cUnit, MIR* mir, int num) } extern RegLocation oatGetRawDest(CompilationUnit* cUnit, MIR* mir) { - DCHECK(mir->ssaRep->numDefs > 0); + DCHECK_GT(mir->ssaRep->numDefs, 0); RegLocation res = cUnit->regLocation[mir->ssaRep->defs[0]]; DCHECK(!res.wide || mir->ssaRep->numDefs == 2); return res; diff --git a/src/compiler/codegen/arm/Assemble.cc b/src/compiler/codegen/arm/Assemble.cc index 86517fa0dd..ede3f6152c 100644 --- a/src/compiler/codegen/arm/Assemble.cc +++ b/src/compiler/codegen/arm/Assemble.cc @@ -1305,7 +1305,7 @@ AssemblerStatus oatAssembleInstructions(CompilationUnit* cUnit, break; case kFmtDfp: { DCHECK(DOUBLEREG(operand)); - DCHECK((operand & 0x1) == 0); + DCHECK_EQ((operand & 0x1), 0U); int regName = (operand & FP_REG_MASK) >> 1; /* Snag the 1-bit slice and position it */ value = ((regName & 0x10) >> 4) << encoder->fieldLoc[i].end; diff --git a/src/compiler/codegen/arm/Thumb2/Factory.cc b/src/compiler/codegen/arm/Thumb2/Factory.cc index c9dbe62cdf..c6cb220107 100644 --- a/src/compiler/codegen/arm/Thumb2/Factory.cc +++ b/src/compiler/codegen/arm/Thumb2/Factory.cc @@ -660,7 +660,7 @@ LIR* loadBaseIndexed(CompilationUnit* cUnit, int rBase, int rIndex, int rDest, } else { DCHECK(DOUBLEREG(rDest)); DCHECK((size == kLong) || (size == kDouble)); - DCHECK((rDest & 0x1) == 0); + DCHECK_EQ((rDest & 0x1), 0); opcode = kThumb2Vldrd; size = kDouble; } @@ -725,7 +725,7 @@ LIR* storeBaseIndexed(CompilationUnit* cUnit, int rBase, int rIndex, int rSrc, } else { DCHECK(DOUBLEREG(rSrc)); DCHECK((size == kLong) || (size == kDouble)); - DCHECK((rSrc & 0x1) == 0); + DCHECK_EQ((rSrc & 0x1), 0); opcode = kThumb2Vstrd; size = kDouble; } diff --git a/src/compiler/codegen/mips/Assemble.cc b/src/compiler/codegen/mips/Assemble.cc index 39ad36b4ad..25e13d7d8f 100644 --- a/src/compiler/codegen/mips/Assemble.cc +++ b/src/compiler/codegen/mips/Assemble.cc @@ -674,7 +674,7 @@ AssemblerStatus oatAssembleInstructions(CompilationUnit *cUnit, break; case kFmtDfp: { DCHECK(DOUBLEREG(operand)); - DCHECK((operand & 0x1) == 0); + DCHECK_EQ((operand & 0x1), 0U); value = ((operand & FP_REG_MASK) << encoder->fieldLoc[i].start) & ((1 << (encoder->fieldLoc[i].end + 1)) - 1); bits |= value; diff --git a/src/compiler/codegen/mips/Codegen.h b/src/compiler/codegen/mips/Codegen.h index 6add82ab0d..106c030b70 100644 --- a/src/compiler/codegen/mips/Codegen.h +++ b/src/compiler/codegen/mips/Codegen.h @@ -67,12 +67,11 @@ void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep, * Must use a core register for data types narrower than word (due * to possible unaligned load/store. */ -inline RegisterClass oatRegClassBySize(OpSize size) -{ +inline RegisterClass oatRegClassBySize(OpSize size) { return (size == kUnsignedHalf || size == kSignedHalf || size == kUnsignedByte || - size == kSignedByte ) ? kCoreReg : kAnyReg; + size == kSignedByte) ? kCoreReg : kAnyReg; } /* @@ -84,7 +83,7 @@ inline RegisterClass oatRegClassBySize(OpSize size) */ #if __BYTE_ORDER == __LITTLE_ENDIAN inline s4 s4FromSwitchData(const void* switchData) { - return *(s4*) switchData; + return *reinterpret_cast<const s4*>(switchData); } #else inline s4 s4FromSwitchData(const void* switchData) { diff --git a/src/compiler/codegen/x86/X86/Factory.cc b/src/compiler/codegen/x86/X86/Factory.cc index 8b02aeddb8..0a02c533b9 100644 --- a/src/compiler/codegen/x86/X86/Factory.cc +++ b/src/compiler/codegen/x86/X86/Factory.cc @@ -58,7 +58,7 @@ LIR *fpRegCopy(CompilationUnit *cUnit, int rDest, int rSrc) { int opcode; /* must be both DOUBLE or both not DOUBLE */ - DCHECK_EQ(DOUBLEREG(rDest),DOUBLEREG(rSrc)); + DCHECK_EQ(DOUBLEREG(rDest), DOUBLEREG(rSrc)); if (DOUBLEREG(rDest)) { opcode = kX86MovsdRR; } else { @@ -73,7 +73,7 @@ LIR *fpRegCopy(CompilationUnit *cUnit, int rDest, int rSrc) opcode = kX86MovdrxRR; } } - DCHECK((EncodingMap[opcode].flags & IS_BINARY_OP) != 0); + DCHECK_NE((EncodingMap[opcode].flags & IS_BINARY_OP), 0); LIR* res = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, rDest, rSrc); if (rDest == rSrc) { res->flags.isNop = true; diff --git a/src/debugger.cc b/src/debugger.cc index 29cb965db6..1dbccccf48 100644 --- a/src/debugger.cc +++ b/src/debugger.cc @@ -952,9 +952,9 @@ static void SetLocation(JDWP::JdwpLocation& location, Method* m, uintptr_t nativ memset(&location, 0, sizeof(location)); } else { Class* c = m->GetDeclaringClass(); - location.typeTag = c->IsInterface() ? JDWP::TT_INTERFACE : JDWP::TT_CLASS; - location.classId = gRegistry->Add(c); - location.methodId = ToMethodId(m); + location.type_tag = c->IsInterface() ? JDWP::TT_INTERFACE : JDWP::TT_CLASS; + location.class_id = gRegistry->Add(c); + location.method_id = ToMethodId(m); location.dex_pc = m->IsNative() ? -1 : m->ToDexPC(native_pc); } } @@ -1736,9 +1736,9 @@ void Dbg::PostLocationEvent(const Method* m, int dex_pc, Object* this_object, in Class* c = m->GetDeclaringClass(); JDWP::JdwpLocation location; - location.typeTag = c->IsInterface() ? JDWP::TT_INTERFACE : JDWP::TT_CLASS; - location.classId = gRegistry->Add(c); - location.methodId = ToMethodId(m); + location.type_tag = c->IsInterface() ? JDWP::TT_INTERFACE : JDWP::TT_CLASS; + location.class_id = gRegistry->Add(c); + location.method_id = ToMethodId(m); location.dex_pc = m->IsNative() ? -1 : dex_pc; // Note we use "NoReg" so we don't keep track of references that are @@ -1905,14 +1905,14 @@ void Dbg::UpdateDebugger(int32_t dex_pc, Thread* self, Method** sp) { void Dbg::WatchLocation(const JDWP::JdwpLocation* location) { MutexLock mu(gBreakpointsLock); - Method* m = FromMethodId(location->methodId); + Method* m = FromMethodId(location->method_id); gBreakpoints.push_back(Breakpoint(m, location->dex_pc)); VLOG(jdwp) << "Set breakpoint #" << (gBreakpoints.size() - 1) << ": " << gBreakpoints[gBreakpoints.size() - 1]; } void Dbg::UnwatchLocation(const JDWP::JdwpLocation* location) { MutexLock mu(gBreakpointsLock); - Method* m = FromMethodId(location->methodId); + Method* m = FromMethodId(location->method_id); for (size_t i = 0; i < gBreakpoints.size(); ++i) { if (gBreakpoints[i].method == m && gBreakpoints[i].dex_pc == location->dex_pc) { VLOG(jdwp) << "Removed breakpoint #" << i << ": " << gBreakpoints[i]; diff --git a/src/disassembler_arm.cc b/src/disassembler_arm.cc index b5ef6a5f91..0472531f91 100644 --- a/src/disassembler_arm.cc +++ b/src/disassembler_arm.cc @@ -93,7 +93,7 @@ static const char* kThumbDataProcessingOperations[] = { }; struct ArmRegister { - ArmRegister(uint32_t r) : r(r) { CHECK_LE(r, 15U); } + explicit ArmRegister(uint32_t r) : r(r) { CHECK_LE(r, 15U); } ArmRegister(uint32_t instruction, uint32_t at_bit) : r((instruction >> at_bit) & 0xf) { CHECK_LE(r, 15U); } uint32_t r; }; @@ -115,7 +115,7 @@ struct ThumbRegister : ArmRegister { }; struct Rm { - Rm(uint32_t instruction) : shift((instruction >> 4) & 0xff), rm(instruction & 0xf) {} + explicit Rm(uint32_t instruction) : shift((instruction >> 4) & 0xff), rm(instruction & 0xf) {} uint32_t shift; ArmRegister rm; }; @@ -128,7 +128,7 @@ std::ostream& operator<<(std::ostream& os, const Rm& r) { } struct ShiftedImmediate { - ShiftedImmediate(uint32_t instruction) { + explicit ShiftedImmediate(uint32_t instruction) { uint32_t rotate = ((instruction >> 8) & 0xf); uint32_t imm = (instruction & 0xff); value = (imm >> (2 * rotate)) | (imm << (32 - (2 * rotate))); @@ -141,7 +141,7 @@ std::ostream& operator<<(std::ostream& os, const ShiftedImmediate& rhs) { } struct RegisterList { - RegisterList(uint32_t instruction) : register_list(instruction & 0xffff) {} + explicit RegisterList(uint32_t instruction) : register_list(instruction & 0xffff) {} uint32_t register_list; }; std::ostream& operator<<(std::ostream& os, const RegisterList& rhs) { diff --git a/src/jdwp/jdwp.h b/src/jdwp/jdwp.h index 4e9b0a04c1..7940566ce6 100644 --- a/src/jdwp/jdwp.h +++ b/src/jdwp/jdwp.h @@ -73,9 +73,9 @@ static inline void expandBufAddFrameId(ExpandBuf* pReply, FrameId id) { expandBu * Holds a JDWP "location". */ struct JdwpLocation { - JdwpTypeTag typeTag; - RefTypeId classId; - MethodId methodId; + JdwpTypeTag type_tag; + RefTypeId class_id; + MethodId method_id; uint64_t dex_pc; }; std::ostream& operator<<(std::ostream& os, const JdwpLocation& rhs); @@ -274,9 +274,9 @@ struct JdwpState { int* pMatchCount) EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_); void UnregisterEvent(JdwpEvent* pEvent) EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_); -public: // TODO: fix privacy + public: // TODO: fix privacy const JdwpOptions* options_; -private: + private: /* wait for creation of the JDWP thread */ Mutex thread_start_lock_; @@ -285,15 +285,15 @@ private: volatile int32_t debug_thread_started_; pthread_t pthread_; Thread* thread_; -public: // TODO: fix privacy + public: // TODO: fix privacy ObjectId debugThreadId; -private: + private: bool run; const JdwpTransport* transport; -public: // TODO: fix privacy + public: // TODO: fix privacy JdwpNetState* netState; -private: + private: /* for wait-for-debugger */ Mutex attach_lock_; @@ -310,11 +310,11 @@ private: /* * Events requested by the debugger (breakpoints, class prep, etc). */ -public: // TODO: fix privacy + public: // TODO: fix privacy Mutex event_list_lock_; JdwpEvent* event_list_ GUARDED_BY(event_list_lock_); // Linked list of events. int event_list_size_ GUARDED_BY(event_list_lock_); // Number of elements in event_list_. -private: + private: /* * Synchronize suspension of event thread (to avoid receiving "resume" @@ -327,9 +327,8 @@ private: /* * DDM support. */ -public: // TODO: fix privacy + public: // TODO: fix privacy bool ddmActive; -private: }; } // namespace JDWP diff --git a/src/jdwp/jdwp_adb.cc b/src/jdwp/jdwp_adb.cc index 096ebc7ec3..4577b590b2 100644 --- a/src/jdwp/jdwp_adb.cc +++ b/src/jdwp/jdwp_adb.cc @@ -48,9 +48,6 @@ #define kInputBufferSize 8192 -#define kMagicHandshake "JDWP-Handshake" -#define kMagicHandshakeLen (sizeof(kMagicHandshake)-1) - #define kJdwpControlName "\0jdwp-control" #define kJdwpControlNameLen (sizeof(kJdwpControlName)-1) @@ -64,7 +61,7 @@ struct JdwpNetState : public JdwpNetStateBase { bool shuttingDown; int wakeFds[2]; - int inputCount; + size_t inputCount; unsigned char inputBuffer[kInputBufferSize]; socklen_t controlAddrLen; @@ -382,12 +379,12 @@ static bool awaitingHandshake(JdwpState* state) { */ static bool haveFullPacket(JdwpNetState* netState) { if (netState->awaitingHandshake) { - return (netState->inputCount >= (int) kMagicHandshakeLen); + return (netState->inputCount >= kMagicHandshakeLen); } if (netState->inputCount < 4) { return false; } - long length = Get4BE(netState->inputBuffer); + uint32_t length = Get4BE(netState->inputBuffer); return (netState->inputCount >= length); } @@ -397,8 +394,8 @@ static bool haveFullPacket(JdwpNetState* netState) { * This would be more efficient with a circular buffer. However, we're * usually only going to find one packet, which is trivial to handle. */ -static void consumeBytes(JdwpNetState* netState, int count) { - CHECK_GT(count, 0); +static void consumeBytes(JdwpNetState* netState, size_t count) { + CHECK_GT(count, 0U); CHECK_LE(count, netState->inputCount); if (count == netState->inputCount) { @@ -437,7 +434,7 @@ static bool handlePacket(JdwpState* state) { cmd = Read1(&buf); } - CHECK_LE((int) length, netState->inputCount); + CHECK_LE(length, netState->inputCount); dataLen = length - (buf - netState->inputBuffer); if (!reply) { diff --git a/src/jdwp/jdwp_event.cc b/src/jdwp/jdwp_event.cc index a92590d62c..f398066bb2 100644 --- a/src/jdwp/jdwp_event.cc +++ b/src/jdwp/jdwp_event.cc @@ -711,10 +711,10 @@ bool JdwpState::PostLocationEvent(const JdwpLocation* pLoc, ObjectId thisPtr, in memset(&basket, 0, sizeof(basket)); basket.pLoc = pLoc; - basket.classId = pLoc->classId; + basket.classId = pLoc->class_id; basket.thisPtr = thisPtr; basket.threadId = Dbg::GetThreadSelfId(); - basket.className = Dbg::GetClassName(pLoc->classId); + basket.className = Dbg::GetClassName(pLoc->class_id); /* * On rare occasions we may need to execute interpreted code in the VM @@ -766,7 +766,7 @@ bool JdwpState::PostLocationEvent(const JdwpLocation* pLoc, ObjectId thisPtr, in } if (match_count != 0) { VLOG(jdwp) << "EVENT: " << match_list[0]->eventKind << "(" << match_count << " total) " - << basket.className << "." << Dbg::GetMethodName(pLoc->classId, pLoc->methodId) + << basket.className << "." << Dbg::GetMethodName(pLoc->class_id, pLoc->method_id) << StringPrintf(" thread=%#llx dex_pc=%#llx)", basket.threadId, pLoc->dex_pc); suspend_policy = scanSuspendPolicy(match_list, match_count); @@ -904,18 +904,17 @@ bool JdwpState::PostVMDeath() { * up the debugger. */ bool JdwpState::PostException(const JdwpLocation* pThrowLoc, - ObjectId exceptionId, RefTypeId exceptionClassId, - const JdwpLocation* pCatchLoc, ObjectId thisPtr) -{ + ObjectId exceptionId, RefTypeId exceptionClassId, + const JdwpLocation* pCatchLoc, ObjectId thisPtr) { ModBasket basket; memset(&basket, 0, sizeof(basket)); basket.pLoc = pThrowLoc; - basket.classId = pThrowLoc->classId; + basket.classId = pThrowLoc->class_id; basket.threadId = Dbg::GetThreadSelfId(); basket.className = Dbg::GetClassName(basket.classId); basket.excepClassId = exceptionClassId; - basket.caught = (pCatchLoc->classId != 0); + basket.caught = (pCatchLoc->class_id != 0); basket.thisPtr = thisPtr; /* don't try to post an exception caused by the debugger */ @@ -938,7 +937,7 @@ bool JdwpState::PostException(const JdwpLocation* pThrowLoc, << StringPrintf(" exceptId=%#llx", exceptionId) << " caught=" << basket.caught << ")" << " throw: " << *pThrowLoc; - if (pCatchLoc->classId == 0) { + if (pCatchLoc->class_id == 0) { VLOG(jdwp) << " catch: (not caught)"; } else { VLOG(jdwp) << " catch: " << *pCatchLoc; diff --git a/src/jdwp/jdwp_handler.cc b/src/jdwp/jdwp_handler.cc index 05fc97946e..f873da201d 100644 --- a/src/jdwp/jdwp_handler.cc +++ b/src/jdwp/jdwp_handler.cc @@ -49,9 +49,9 @@ namespace JDWP { */ static void jdwpReadLocation(const uint8_t** pBuf, JdwpLocation* pLoc) { memset(pLoc, 0, sizeof(*pLoc)); /* allows memcmp() later */ - pLoc->typeTag = ReadTypeTag(pBuf); - pLoc->classId = ReadObjectId(pBuf); - pLoc->methodId = ReadMethodId(pBuf); + pLoc->type_tag = ReadTypeTag(pBuf); + pLoc->class_id = ReadObjectId(pBuf); + pLoc->method_id = ReadMethodId(pBuf); pLoc->dex_pc = Read8BE(pBuf); } @@ -59,9 +59,9 @@ static void jdwpReadLocation(const uint8_t** pBuf, JdwpLocation* pLoc) { * Helper function: write a "location" into the reply buffer. */ void AddLocation(ExpandBuf* pReply, const JdwpLocation* pLoc) { - expandBufAdd1(pReply, pLoc->typeTag); - expandBufAddObjectId(pReply, pLoc->classId); - expandBufAddMethodId(pReply, pLoc->methodId); + expandBufAdd1(pReply, pLoc->type_tag); + expandBufAddObjectId(pReply, pLoc->class_id); + expandBufAddMethodId(pReply, pLoc->method_id); expandBufAdd8BE(pReply, pLoc->dex_pc); } @@ -96,20 +96,18 @@ static void jdwpWriteValue(ExpandBuf* pReply, int width, uint64_t value) { /* * Common code for *_InvokeMethod requests. * - * If "is_constructor" is set, this returns "objectId" rather than the + * If "is_constructor" is set, this returns "object_id" rather than the * expected-to-be-void return value of the called function. */ -static JdwpError finishInvoke(JdwpState*, - const uint8_t* buf, int, ExpandBuf* pReply, - ObjectId threadId, ObjectId objectId, RefTypeId classId, MethodId methodId, - bool is_constructor) -{ - CHECK(!is_constructor || objectId != 0); +static JdwpError finishInvoke(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply, + ObjectId thread_id, ObjectId object_id, + RefTypeId class_id, MethodId method_id, bool is_constructor) { + CHECK(!is_constructor || object_id != 0); uint32_t arg_count = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" --> threadId=%#llx objectId=%#llx", threadId, objectId); - VLOG(jdwp) << StringPrintf(" classId=%#llx methodId=%x %s.%s", classId, methodId, Dbg::GetClassName(classId).c_str(), Dbg::GetMethodName(classId, methodId).c_str()); + VLOG(jdwp) << StringPrintf(" --> thread_id=%#llx object_id=%#llx", thread_id, object_id); + VLOG(jdwp) << StringPrintf(" class_id=%#llx method_id=%x %s.%s", class_id, method_id, Dbg::GetClassName(class_id).c_str(), Dbg::GetMethodName(class_id, method_id).c_str()); VLOG(jdwp) << StringPrintf(" %d args:", arg_count); UniquePtr<JdwpTag[]> argTypes(arg_count > 0 ? new JdwpTag[arg_count] : NULL); @@ -127,7 +125,7 @@ static JdwpError finishInvoke(JdwpState*, JdwpTag resultTag; uint64_t resultValue; ObjectId exceptObjId; - JdwpError err = Dbg::InvokeMethod(threadId, objectId, classId, methodId, arg_count, argValues.get(), argTypes.get(), options, &resultTag, &resultValue, &exceptObjId); + JdwpError err = Dbg::InvokeMethod(thread_id, object_id, class_id, method_id, arg_count, argValues.get(), argTypes.get(), options, &resultTag, &resultValue, &exceptObjId); if (err != ERR_NONE) { return err; } @@ -137,7 +135,7 @@ static JdwpError finishInvoke(JdwpState*, // If we invoked a constructor (which actually returns void), return the receiver, // unless we threw, in which case we return NULL. resultTag = JT_OBJECT; - resultValue = (exceptObjId == 0) ? objectId : 0; + resultValue = (exceptObjId == 0) ? object_id : 0; } size_t width = Dbg::GetTagWidth(resultTag); @@ -600,9 +598,9 @@ static JdwpError handleRT_Methods(JdwpState*, const uint8_t* buf, int, ExpandBuf * Return the immediate superclass of a class. */ static JdwpError handleCT_Superclass(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - RefTypeId classId = ReadRefTypeId(&buf); + RefTypeId class_id = ReadRefTypeId(&buf); RefTypeId superClassId; - JdwpError status = Dbg::GetSuperclass(classId, superClassId); + JdwpError status = Dbg::GetSuperclass(class_id, superClassId); if (status != ERR_NONE) { return status; } @@ -614,10 +612,10 @@ static JdwpError handleCT_Superclass(JdwpState*, const uint8_t* buf, int, Expand * Set static class values. */ static JdwpError handleCT_SetValues(JdwpState* , const uint8_t* buf, int, ExpandBuf*) { - RefTypeId classId = ReadRefTypeId(&buf); + RefTypeId class_id = ReadRefTypeId(&buf); uint32_t values = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" Req to set %d values in classId=%#llx", values, classId); + VLOG(jdwp) << StringPrintf(" Req to set %d values in class_id=%#llx", values, class_id); for (uint32_t i = 0; i < values; i++) { FieldId fieldId = ReadFieldId(&buf); @@ -642,11 +640,11 @@ static JdwpError handleCT_SetValues(JdwpState* , const uint8_t* buf, int, Expand * values in the "variables" display. */ static JdwpError handleCT_InvokeMethod(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { - RefTypeId classId = ReadRefTypeId(&buf); - ObjectId threadId = ReadObjectId(&buf); - MethodId methodId = ReadMethodId(&buf); + RefTypeId class_id = ReadRefTypeId(&buf); + ObjectId thread_id = ReadObjectId(&buf); + MethodId method_id = ReadMethodId(&buf); - return finishInvoke(state, buf, dataLen, pReply, threadId, 0, classId, methodId, false); + return finishInvoke(state, buf, dataLen, pReply, thread_id, 0, class_id, method_id, false); } /* @@ -657,20 +655,20 @@ static JdwpError handleCT_InvokeMethod(JdwpState* state, const uint8_t* buf, int * see the contents of a byte[] as a string. */ static JdwpError handleCT_NewInstance(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { - RefTypeId classId = ReadRefTypeId(&buf); - ObjectId threadId = ReadObjectId(&buf); - MethodId methodId = ReadMethodId(&buf); + RefTypeId class_id = ReadRefTypeId(&buf); + ObjectId thread_id = ReadObjectId(&buf); + MethodId method_id = ReadMethodId(&buf); - VLOG(jdwp) << "Creating instance of " << Dbg::GetClassName(classId); - ObjectId objectId; - JdwpError status = Dbg::CreateObject(classId, objectId); + VLOG(jdwp) << "Creating instance of " << Dbg::GetClassName(class_id); + ObjectId object_id; + JdwpError status = Dbg::CreateObject(class_id, object_id); if (status != ERR_NONE) { return status; } - if (objectId == 0) { + if (object_id == 0) { return ERR_OUT_OF_MEMORY; } - return finishInvoke(state, buf, dataLen, pReply, threadId, objectId, classId, methodId, true); + return finishInvoke(state, buf, dataLen, pReply, thread_id, object_id, class_id, method_id, true); } /* @@ -681,16 +679,16 @@ static JdwpError handleAT_newInstance(JdwpState*, const uint8_t* buf, int, Expan uint32_t length = Read4BE(&buf); VLOG(jdwp) << "Creating array " << Dbg::GetClassName(arrayTypeId) << "[" << length << "]"; - ObjectId objectId; - JdwpError status = Dbg::CreateArrayObject(arrayTypeId, length, objectId); + ObjectId object_id; + JdwpError status = Dbg::CreateArrayObject(arrayTypeId, length, object_id); if (status != ERR_NONE) { return status; } - if (objectId == 0) { + if (object_id == 0) { return ERR_OUT_OF_MEMORY; } expandBufAdd1(pReply, JT_ARRAY); - expandBufAddObjectId(pReply, objectId); + expandBufAddObjectId(pReply, object_id); return ERR_NONE; } @@ -699,26 +697,26 @@ static JdwpError handleAT_newInstance(JdwpState*, const uint8_t* buf, int, Expan */ static JdwpError handleM_LineTable(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { RefTypeId refTypeId = ReadRefTypeId(&buf); - MethodId methodId = ReadMethodId(&buf); + MethodId method_id = ReadMethodId(&buf); - VLOG(jdwp) << " Req for line table in " << Dbg::GetClassName(refTypeId) << "." << Dbg::GetMethodName(refTypeId,methodId); + VLOG(jdwp) << " Req for line table in " << Dbg::GetClassName(refTypeId) << "." << Dbg::GetMethodName(refTypeId, method_id); - Dbg::OutputLineTable(refTypeId, methodId, pReply); + Dbg::OutputLineTable(refTypeId, method_id, pReply); return ERR_NONE; } static JdwpError handleM_VariableTable(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply, bool generic) { - RefTypeId classId = ReadRefTypeId(&buf); - MethodId methodId = ReadMethodId(&buf); + RefTypeId class_id = ReadRefTypeId(&buf); + MethodId method_id = ReadMethodId(&buf); - VLOG(jdwp) << StringPrintf(" Req for LocalVarTab in class=%s method=%s", Dbg::GetClassName(classId).c_str(), Dbg::GetMethodName(classId, methodId).c_str()); + VLOG(jdwp) << StringPrintf(" Req for LocalVarTab in class=%s method=%s", Dbg::GetClassName(class_id).c_str(), Dbg::GetMethodName(class_id, method_id).c_str()); // We could return ERR_ABSENT_INFORMATION here if the DEX file was built without local variable // information. That will cause Eclipse to make a best-effort attempt at displaying local // variables anonymously. However, the attempt isn't very good, so we're probably better off just // not showing anything. - Dbg::OutputVariableTable(classId, methodId, generic, pReply); + Dbg::OutputVariableTable(class_id, method_id, generic, pReply); return ERR_NONE; } @@ -734,29 +732,29 @@ static JdwpError handleM_VariableTableWithGeneric(JdwpState* state, const uint8_ * Given an object reference, return the runtime type of the object * (class or array). * - * This can get called on different things, e.g. threadId gets + * This can get called on different things, e.g. thread_id gets * passed in here. */ static JdwpError handleOR_ReferenceType(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId objectId = ReadObjectId(&buf); - VLOG(jdwp) << StringPrintf(" Req for type of objectId=%#llx", objectId); - return Dbg::GetReferenceType(objectId, pReply); + ObjectId object_id = ReadObjectId(&buf); + VLOG(jdwp) << StringPrintf(" Req for type of object_id=%#llx", object_id); + return Dbg::GetReferenceType(object_id, pReply); } /* * Get values from the fields of an object. */ static JdwpError handleOR_GetValues(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId objectId = ReadObjectId(&buf); + ObjectId object_id = ReadObjectId(&buf); uint32_t field_count = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" Req for %d fields from objectId=%#llx", field_count, objectId); + VLOG(jdwp) << StringPrintf(" Req for %d fields from object_id=%#llx", field_count, object_id); expandBufAdd4BE(pReply, field_count); for (uint32_t i = 0; i < field_count; i++) { FieldId fieldId = ReadFieldId(&buf); - JdwpError status = Dbg::GetFieldValue(objectId, fieldId, pReply); + JdwpError status = Dbg::GetFieldValue(object_id, fieldId, pReply); if (status != ERR_NONE) { return status; } @@ -769,10 +767,10 @@ static JdwpError handleOR_GetValues(JdwpState*, const uint8_t* buf, int, ExpandB * Set values in the fields of an object. */ static JdwpError handleOR_SetValues(JdwpState*, const uint8_t* buf, int, ExpandBuf*) { - ObjectId objectId = ReadObjectId(&buf); + ObjectId object_id = ReadObjectId(&buf); uint32_t field_count = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" Req to set %d fields in objectId=%#llx", field_count, objectId); + VLOG(jdwp) << StringPrintf(" Req to set %d fields in object_id=%#llx", field_count, object_id); for (uint32_t i = 0; i < field_count; i++) { FieldId fieldId = ReadFieldId(&buf); @@ -782,7 +780,7 @@ static JdwpError handleOR_SetValues(JdwpState*, const uint8_t* buf, int, ExpandB uint64_t value = jdwpReadValue(&buf, width); VLOG(jdwp) << " --> fieldId=" << fieldId << " tag=" << fieldTag << "(" << width << ") value=" << value; - JdwpError status = Dbg::SetFieldValue(objectId, fieldId, value, width); + JdwpError status = Dbg::SetFieldValue(object_id, fieldId, value, width); if (status != ERR_NONE) { return status; } @@ -803,12 +801,12 @@ static JdwpError handleOR_SetValues(JdwpState*, const uint8_t* buf, int, ExpandB * feature becomes crucial when examining ArrayLists with Eclipse. */ static JdwpError handleOR_InvokeMethod(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { - ObjectId objectId = ReadObjectId(&buf); - ObjectId threadId = ReadObjectId(&buf); - RefTypeId classId = ReadRefTypeId(&buf); - MethodId methodId = ReadMethodId(&buf); + ObjectId object_id = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); + RefTypeId class_id = ReadRefTypeId(&buf); + MethodId method_id = ReadMethodId(&buf); - return finishInvoke(state, buf, dataLen, pReply, threadId, objectId, classId, methodId, false); + return finishInvoke(state, buf, dataLen, pReply, thread_id, object_id, class_id, method_id, false); } /* @@ -831,10 +829,10 @@ static JdwpError handleOR_EnableCollection(JdwpState*, const uint8_t*, int, Expa * Determine whether an object has been garbage collected. */ static JdwpError handleOR_IsCollected(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId objectId; + ObjectId object_id; - objectId = ReadObjectId(&buf); - VLOG(jdwp) << StringPrintf(" Req IsCollected(%#llx)", objectId); + object_id = ReadObjectId(&buf); + VLOG(jdwp) << StringPrintf(" Req IsCollected(%#llx)", object_id); // TODO: currently returning false; must integrate with GC expandBufAdd1(pReply, 0); @@ -860,14 +858,14 @@ static JdwpError handleSR_Value(JdwpState*, const uint8_t* buf, int, ExpandBuf* * Return a thread's name. */ static JdwpError handleTR_Name(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); - VLOG(jdwp) << StringPrintf(" Req for name of thread %#llx", threadId); + VLOG(jdwp) << StringPrintf(" Req for name of thread %#llx", thread_id); std::string name; - if (!Dbg::GetThreadName(threadId, name)) { + if (!Dbg::GetThreadName(thread_id, name)) { return ERR_INVALID_THREAD; } - VLOG(jdwp) << StringPrintf(" Name of thread %#llx is \"%s\"", threadId, name.c_str()); + VLOG(jdwp) << StringPrintf(" Name of thread %#llx is \"%s\"", thread_id, name.c_str()); expandBufAddUtf8String(pReply, name); return ERR_NONE; @@ -880,14 +878,14 @@ static JdwpError handleTR_Name(JdwpState*, const uint8_t* buf, int, ExpandBuf* p * resume it; only the JDI is allowed to resume it. */ static JdwpError handleTR_Suspend(JdwpState*, const uint8_t* buf, int, ExpandBuf*) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); - if (threadId == Dbg::GetThreadSelfId()) { + if (thread_id == Dbg::GetThreadSelfId()) { LOG(INFO) << " Warning: ignoring request to suspend self"; return ERR_THREAD_NOT_SUSPENDED; } - VLOG(jdwp) << StringPrintf(" Req to suspend thread %#llx", threadId); - Dbg::SuspendThread(threadId); + VLOG(jdwp) << StringPrintf(" Req to suspend thread %#llx", thread_id); + Dbg::SuspendThread(thread_id); return ERR_NONE; } @@ -895,14 +893,14 @@ static JdwpError handleTR_Suspend(JdwpState*, const uint8_t* buf, int, ExpandBuf * Resume the specified thread. */ static JdwpError handleTR_Resume(JdwpState*, const uint8_t* buf, int, ExpandBuf*) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); - if (threadId == Dbg::GetThreadSelfId()) { + if (thread_id == Dbg::GetThreadSelfId()) { LOG(INFO) << " Warning: ignoring request to resume self"; return ERR_NONE; } - VLOG(jdwp) << StringPrintf(" Req to resume thread %#llx", threadId); - Dbg::ResumeThread(threadId); + VLOG(jdwp) << StringPrintf(" Req to resume thread %#llx", thread_id); + Dbg::ResumeThread(thread_id); return ERR_NONE; } @@ -910,13 +908,13 @@ static JdwpError handleTR_Resume(JdwpState*, const uint8_t* buf, int, ExpandBuf* * Return status of specified thread. */ static JdwpError handleTR_Status(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); - VLOG(jdwp) << StringPrintf(" Req for status of thread %#llx", threadId); + VLOG(jdwp) << StringPrintf(" Req for status of thread %#llx", thread_id); JDWP::JdwpThreadStatus threadStatus; JDWP::JdwpSuspendStatus suspendStatus; - if (!Dbg::GetThreadStatus(threadId, &threadStatus, &suspendStatus)) { + if (!Dbg::GetThreadStatus(thread_id, &threadStatus, &suspendStatus)) { return ERR_INVALID_THREAD; } @@ -932,8 +930,8 @@ static JdwpError handleTR_Status(JdwpState*, const uint8_t* buf, int, ExpandBuf* * Return the thread group that the specified thread is a member of. */ static JdwpError handleTR_ThreadGroup(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); - return Dbg::GetThreadGroup(threadId, pReply); + ObjectId thread_id = ReadObjectId(&buf); + return Dbg::GetThreadGroup(thread_id, pReply); } /* @@ -943,21 +941,21 @@ static JdwpError handleTR_ThreadGroup(JdwpState*, const uint8_t* buf, int, Expan * be THREAD_NOT_SUSPENDED. */ static JdwpError handleTR_Frames(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); uint32_t start_frame = Read4BE(&buf); uint32_t length = Read4BE(&buf); - if (!Dbg::ThreadExists(threadId)) { + if (!Dbg::ThreadExists(thread_id)) { return ERR_INVALID_THREAD; } - if (!Dbg::IsSuspended(threadId)) { - LOG(WARNING) << StringPrintf(" Rejecting req for frames in running thread %#llx", threadId); + if (!Dbg::IsSuspended(thread_id)) { + LOG(WARNING) << StringPrintf(" Rejecting req for frames in running thread %#llx", thread_id); return ERR_THREAD_NOT_SUSPENDED; } - size_t actual_frame_count = Dbg::GetThreadFrameCount(threadId); + size_t actual_frame_count = Dbg::GetThreadFrameCount(thread_id); - VLOG(jdwp) << StringPrintf(" Request for frames: threadId=%#llx start=%d length=%d [count=%zd]", threadId, start_frame, length, actual_frame_count); + VLOG(jdwp) << StringPrintf(" Request for frames: thread_id=%#llx start=%d length=%d [count=%zd]", thread_id, start_frame, length, actual_frame_count); if (actual_frame_count <= 0) { return ERR_THREAD_NOT_SUSPENDED; /* == 0 means 100% native */ } @@ -978,7 +976,7 @@ static JdwpError handleTR_Frames(JdwpState*, const uint8_t* buf, int, ExpandBuf* JdwpLocation loc; // TODO: switch to GetThreadFrames so we don't have to search for each frame // even though we only want them in order. - Dbg::GetThreadFrame(threadId, i, &frame_id, &loc); + Dbg::GetThreadFrame(thread_id, i, &frame_id, &loc); expandBufAdd8BE(pReply, frame_id); AddLocation(pReply, &loc); @@ -993,17 +991,17 @@ static JdwpError handleTR_Frames(JdwpState*, const uint8_t* buf, int, ExpandBuf* * Returns the #of frames on the specified thread, which must be suspended. */ static JdwpError handleTR_FrameCount(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); - if (!Dbg::ThreadExists(threadId)) { + if (!Dbg::ThreadExists(thread_id)) { return ERR_INVALID_THREAD; } - if (!Dbg::IsSuspended(threadId)) { - LOG(WARNING) << StringPrintf(" Rejecting req for frames in running thread %#llx", threadId); + if (!Dbg::IsSuspended(thread_id)) { + LOG(WARNING) << StringPrintf(" Rejecting req for frames in running thread %#llx", thread_id); return ERR_THREAD_NOT_SUSPENDED; } - int frame_count = Dbg::GetThreadFrameCount(threadId); + int frame_count = Dbg::GetThreadFrameCount(thread_id); if (frame_count < 0) { return ERR_INVALID_THREAD; } @@ -1016,7 +1014,7 @@ static JdwpError handleTR_FrameCount(JdwpState*, const uint8_t* buf, int, Expand * Get the monitor that the thread is waiting on. */ static JdwpError handleTR_CurrentContendedMonitor(JdwpState*, const uint8_t* buf, int, ExpandBuf*) { - ReadObjectId(&buf); // threadId + ReadObjectId(&buf); // thread_id // TODO: create an Object to represent the monitor (we're currently // just using a raw Monitor struct in the VM) @@ -1031,8 +1029,8 @@ static JdwpError handleTR_CurrentContendedMonitor(JdwpState*, const uint8_t* buf * its suspend count recently.) */ static JdwpError handleTR_SuspendCount(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); - return Dbg::GetThreadSuspendCount(threadId, pReply); + ObjectId thread_id = ReadObjectId(&buf); + return Dbg::GetThreadSuspendCount(thread_id, pReply); } /* @@ -1198,16 +1196,16 @@ static JdwpError handleER_Set(JdwpState* state, const uint8_t* buf, int dataLen, break; case MK_THREAD_ONLY: /* only report events in specified thread */ { - ObjectId threadId = ReadObjectId(&buf); - VLOG(jdwp) << StringPrintf(" ThreadOnly: %#llx", threadId); - mod.threadOnly.threadId = threadId; + ObjectId thread_id = ReadObjectId(&buf); + VLOG(jdwp) << StringPrintf(" ThreadOnly: %#llx", thread_id); + mod.threadOnly.threadId = thread_id; } break; case MK_CLASS_ONLY: /* for ClassPrepare, MethodEntry */ { - RefTypeId classId = ReadRefTypeId(&buf); - VLOG(jdwp) << StringPrintf(" ClassOnly: %#llx (%s)", classId, Dbg::GetClassName(classId).c_str()); - mod.classOnly.refTypeId = classId; + RefTypeId class_id = ReadRefTypeId(&buf); + VLOG(jdwp) << StringPrintf(" ClassOnly: %#llx (%s)", class_id, Dbg::GetClassName(class_id).c_str()); + mod.classOnly.refTypeId = class_id; } break; case MK_CLASS_MATCH: /* restrict events to matching classes */ @@ -1263,16 +1261,16 @@ static JdwpError handleER_Set(JdwpState* state, const uint8_t* buf, int dataLen, break; case MK_STEP: /* for use with EK_SINGLE_STEP */ { - ObjectId threadId; + ObjectId thread_id; uint32_t size, depth; - threadId = ReadObjectId(&buf); + thread_id = ReadObjectId(&buf); size = Read4BE(&buf); depth = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" Step: thread=%#llx", threadId) + VLOG(jdwp) << StringPrintf(" Step: thread=%#llx", thread_id) << " size=" << JdwpStepSize(size) << " depth=" << JdwpStepDepth(depth); - mod.step.threadId = threadId; + mod.step.threadId = thread_id; mod.step.size = size; mod.step.depth = depth; } @@ -1338,11 +1336,11 @@ static JdwpError handleER_Clear(JdwpState* state, const uint8_t* buf, int, Expan * Return the values of arguments and local variables. */ static JdwpError handleSF_GetValues(JdwpState*, const uint8_t* buf, int, ExpandBuf* pReply) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); FrameId frame_id = ReadFrameId(&buf); uint32_t slots = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" Req for %d slots in threadId=%#llx frame_id=%#llx", slots, threadId, frame_id); + VLOG(jdwp) << StringPrintf(" Req for %d slots in thread_id=%#llx frame_id=%#llx", slots, thread_id, frame_id); expandBufAdd4BE(pReply, slots); /* "int values" */ for (uint32_t i = 0; i < slots; i++) { @@ -1353,7 +1351,7 @@ static JdwpError handleSF_GetValues(JdwpState*, const uint8_t* buf, int, ExpandB size_t width = Dbg::GetTagWidth(reqSigByte); uint8_t* ptr = expandBufAddSpace(pReply, width+1); - Dbg::GetLocalValue(threadId, frame_id, slot, reqSigByte, ptr, width); + Dbg::GetLocalValue(thread_id, frame_id, slot, reqSigByte, ptr, width); } return ERR_NONE; @@ -1363,11 +1361,11 @@ static JdwpError handleSF_GetValues(JdwpState*, const uint8_t* buf, int, ExpandB * Set the values of arguments and local variables. */ static JdwpError handleSF_SetValues(JdwpState*, const uint8_t* buf, int, ExpandBuf*) { - ObjectId threadId = ReadObjectId(&buf); + ObjectId thread_id = ReadObjectId(&buf); FrameId frame_id = ReadFrameId(&buf); uint32_t slots = Read4BE(&buf); - VLOG(jdwp) << StringPrintf(" Req to set %d slots in threadId=%#llx frame_id=%#llx", slots, threadId, frame_id); + VLOG(jdwp) << StringPrintf(" Req to set %d slots in thread_id=%#llx frame_id=%#llx", slots, thread_id, frame_id); for (uint32_t i = 0; i < slots; i++) { uint32_t slot = Read4BE(&buf); @@ -1376,7 +1374,7 @@ static JdwpError handleSF_SetValues(JdwpState*, const uint8_t* buf, int, ExpandB uint64_t value = jdwpReadValue(&buf, width); VLOG(jdwp) << " --> slot " << slot << " " << sigByte << " " << value; - Dbg::SetLocalValue(threadId, frame_id, slot, sigByte, value, width); + Dbg::SetLocalValue(thread_id, frame_id, slot, sigByte, value, width); } return ERR_NONE; @@ -1560,7 +1558,7 @@ static const JdwpHandlerMap gHandlerMap[] = { { 11, 8, NULL, "ThreadReference.OwnedMonitors" }, { 11, 9, handleTR_CurrentContendedMonitor, "ThreadReference.CurrentContendedMonitor" }, { 11, 10, NULL, "ThreadReference.Stop" }, - { 11, 11, NULL,"ThreadReference.Interrupt" }, + { 11, 11, NULL, "ThreadReference.Interrupt" }, { 11, 12, handleTR_SuspendCount, "ThreadReference.SuspendCount" }, { 11, 13, NULL, "ThreadReference.OwnedMonitorsStackDepthInfo" }, { 11, 14, NULL, "ThreadReference.ForceEarlyReturn" }, @@ -1590,7 +1588,7 @@ static const JdwpHandlerMap gHandlerMap[] = { { 16, 4, NULL, "StackFrame.PopFrames" }, /* ClassObjectReference command set (17) */ - { 17, 1, handleCOR_ReflectedType,"ClassObjectReference.ReflectedType" }, + { 17, 1, handleCOR_ReflectedType, "ClassObjectReference.ReflectedType" }, /* Event command set (64) */ { 64, 100, NULL, "Event.Composite" }, // sent from VM to debugger, never received by VM @@ -1599,7 +1597,7 @@ static const JdwpHandlerMap gHandlerMap[] = { }; static const char* GetCommandName(size_t cmdSet, size_t cmd) { - for (int i = 0; i < (int) arraysize(gHandlerMap); i++) { + for (size_t i = 0; i < arraysize(gHandlerMap); ++i) { if (gHandlerMap[i].cmdSet == cmdSet && gHandlerMap[i].cmd == cmd) { return gHandlerMap[i].descr; } diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc index fb24e297d7..20b770fce3 100644 --- a/src/jdwp/jdwp_main.cc +++ b/src/jdwp/jdwp_main.cc @@ -438,14 +438,14 @@ int64_t JdwpState::LastDebuggerActivity() { std::ostream& operator<<(std::ostream& os, const JdwpLocation& rhs) { os << "JdwpLocation[" - << Dbg::GetClassName(rhs.classId) << "." << Dbg::GetMethodName(rhs.classId, rhs.methodId) - << "@" << StringPrintf("%#llx", rhs.dex_pc) << " " << rhs.typeTag << "]"; + << Dbg::GetClassName(rhs.class_id) << "." << Dbg::GetMethodName(rhs.class_id, rhs.method_id) + << "@" << StringPrintf("%#llx", rhs.dex_pc) << " " << rhs.type_tag << "]"; return os; } bool operator==(const JdwpLocation& lhs, const JdwpLocation& rhs) { - return lhs.dex_pc == rhs.dex_pc && lhs.methodId == rhs.methodId && - lhs.classId == rhs.classId && lhs.typeTag == rhs.typeTag; + return lhs.dex_pc == rhs.dex_pc && lhs.method_id == rhs.method_id && + lhs.class_id == rhs.class_id && lhs.type_tag == rhs.type_tag; } bool operator!=(const JdwpLocation& lhs, const JdwpLocation& rhs) { diff --git a/src/jdwp/jdwp_priv.h b/src/jdwp/jdwp_priv.h index 7a6a5284bf..98ae3b9aba 100644 --- a/src/jdwp/jdwp_priv.h +++ b/src/jdwp/jdwp_priv.h @@ -32,6 +32,9 @@ #define kJDWPHeaderLen 11 #define kJDWPFlagReply 0x80 +#define kMagicHandshake "JDWP-Handshake" +#define kMagicHandshakeLen (sizeof(kMagicHandshake)-1) + /* DDM support */ #define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */ #define kJDWPDdmCmd 1 diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc index 01eba12bb7..4424e7b324 100644 --- a/src/jdwp/jdwp_socket.cc +++ b/src/jdwp/jdwp_socket.cc @@ -38,9 +38,6 @@ #define kInputBufferSize 8192 -#define kMagicHandshake "JDWP-Handshake" -#define kMagicHandshakeLen (sizeof(kMagicHandshake)-1) - namespace art { namespace JDWP { @@ -55,29 +52,29 @@ static void netFree(JdwpNetState* state); * We only talk to one debugger at a time. */ struct JdwpNetState : public JdwpNetStateBase { - uint16_t listenPort; - int listenSock; /* listen for connection from debugger */ - int wakePipe[2]; /* break out of select */ + uint16_t listenPort; + int listenSock; /* listen for connection from debugger */ + int wakePipe[2]; /* break out of select */ - in_addr remoteAddr; - uint16_t remotePort; + in_addr remoteAddr; + uint16_t remotePort; - bool awaitingHandshake; /* waiting for "JDWP-Handshake" */ + bool awaitingHandshake; /* waiting for "JDWP-Handshake" */ - /* pending data from the network; would be more efficient as circular buf */ - unsigned char inputBuffer[kInputBufferSize]; - int inputCount; + /* pending data from the network; would be more efficient as circular buf */ + unsigned char inputBuffer[kInputBufferSize]; + size_t inputCount; - JdwpNetState() { - listenPort = 0; - listenSock = -1; - wakePipe[0] = -1; - wakePipe[1] = -1; + JdwpNetState() { + listenPort = 0; + listenSock = -1; + wakePipe[0] = -1; + wakePipe[1] = -1; - awaitingHandshake = false; + awaitingHandshake = false; - inputCount = 0; - } + inputCount = 0; + } }; static JdwpNetState* netStartup(uint16_t port, bool probe); @@ -265,62 +262,15 @@ static bool isConnected(JdwpState* state) { } /* - * Returns "true" if the fd is ready, "false" if not. - */ -#if 0 -static bool isFdReadable(int sock) -{ - fd_set readfds; - timeval tv; - int count; - - FD_ZERO(&readfds); - FD_SET(sock, &readfds); - - tv.tv_sec = 0; - tv.tv_usec = 0; - count = select(sock+1, &readfds, NULL, NULL, &tv); - if (count <= 0) - return false; - - if (FD_ISSET(sock, &readfds)) /* make sure it's our fd */ - return true; - - LOG(ERROR) << "WEIRD: odd behavior in select (count=" << count << ")"; - return false; -} -#endif - -#if 0 -/* - * Check to see if we have a pending connection from the debugger. - * - * Returns true on success (meaning a connection is available). - */ -static bool checkConnection(JdwpState* state) { - JdwpNetState* netState = state->netState; - - CHECK_GE(netState->listenSock, 0); - /* not expecting to be called when debugger is actively connected */ - CHECK_LT(netState->clientSock, 0); - - if (!isFdReadable(netState->listenSock)) - return false; - return true; -} -#endif - -/* * Disable the TCP Nagle algorithm, which delays transmission of outbound * packets until the previous transmissions have been acked. JDWP does a * lot of back-and-forth with small packets, so this may help. */ -static int setNoDelay(int fd) -{ - int on = 1; - int cc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); - CHECK_EQ(cc, 0); - return cc; +static int setNoDelay(int fd) { + int on = 1; + int cc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); + CHECK_EQ(cc, 0); + return cc; } /* @@ -328,8 +278,7 @@ static int setNoDelay(int fd) * If that's not desirable, use checkConnection() to make sure something * is pending. */ -static bool acceptConnection(JdwpState* state) -{ +static bool acceptConnection(JdwpState* state) { JdwpNetState* netState = state->netState; union { sockaddr_in addrInet; @@ -487,12 +436,12 @@ static void closeConnection(JdwpState* state) { */ static bool haveFullPacket(JdwpNetState* netState) { if (netState->awaitingHandshake) { - return (netState->inputCount >= (int) kMagicHandshakeLen); + return (netState->inputCount >= kMagicHandshakeLen); } if (netState->inputCount < 4) { return false; } - long length = Get4BE(netState->inputBuffer); + uint32_t length = Get4BE(netState->inputBuffer); return (netState->inputCount >= length); } @@ -502,8 +451,8 @@ static bool haveFullPacket(JdwpNetState* netState) { * This would be more efficient with a circular buffer. However, we're * usually only going to find one packet, which is trivial to handle. */ -static void consumeBytes(JdwpNetState* netState, int count) { - CHECK_GT(count, 0); +static void consumeBytes(JdwpNetState* netState, size_t count) { + CHECK_GT(count, 0U); CHECK_LE(count, netState->inputCount); if (count == netState->inputCount) { @@ -516,58 +465,19 @@ static void consumeBytes(JdwpNetState* netState, int count) { } /* - * Dump the contents of a packet to stdout. - */ -#if 0 -static void dumpPacket(const unsigned char* packetBuf) { - const unsigned char* buf = packetBuf; - uint32_t length, id; - uint8_t flags, cmdSet, cmd; - uint16_t error; - bool reply; - int dataLen; - - cmd = cmdSet = 0xcc; - - length = Read4BE(&buf); - id = Read4BE(&buf); - flags = Read1(&buf); - if ((flags & kJDWPFlagReply) != 0) { - reply = true; - error = Read2BE(&buf); - } else { - reply = false; - cmdSet = Read1(&buf); - cmd = Read1(&buf); - } - - dataLen = length - (buf - packetBuf); - - VLOG(jdwp) << StringPrintf("--- %s: dataLen=%u id=0x%08x flags=0x%02x cmd=%d/%d", - reply ? "reply" : "req", dataLen, id, flags, cmdSet, cmd); - VLOG(jdwp) << HexDump(buf, dataLen); -} -#endif - -/* * Handle a packet. Returns "false" if we encounter a connection-fatal error. */ static bool handlePacket(JdwpState* state) { JdwpNetState* netState = state->netState; const unsigned char* buf = netState->inputBuffer; - JdwpReqHeader hdr; - uint32_t length, id; - uint8_t flags, cmdSet, cmd; + uint8_t cmdSet, cmd; bool reply; - int dataLen; cmd = cmdSet = 0; // shut up gcc - /*dumpPacket(netState->inputBuffer);*/ - - length = Read4BE(&buf); - id = Read4BE(&buf); - flags = Read1(&buf); + uint32_t length = Read4BE(&buf); + uint32_t id = Read4BE(&buf); + int8_t flags = Read1(&buf); if ((flags & kJDWPFlagReply) != 0) { reply = true; Read2BE(&buf); // error @@ -577,12 +487,13 @@ static bool handlePacket(JdwpState* state) { cmd = Read1(&buf); } - CHECK_LE((int) length, netState->inputCount); - dataLen = length - (buf - netState->inputBuffer); + CHECK_LE(length, netState->inputCount); + int dataLen = length - (buf - netState->inputBuffer); if (!reply) { ExpandBuf* pReply = expandBufAlloc(); + JdwpReqHeader hdr; hdr.length = length; hdr.id = id; hdr.cmdSet = cmdSet; diff --git a/src/jni_internal.cc b/src/jni_internal.cc index ed46837efc..f3ef3efbfe 100644 --- a/src/jni_internal.cc +++ b/src/jni_internal.cc @@ -93,7 +93,7 @@ T AddLocalReference(JNIEnv* public_env, const Object* const_obj) { return NULL; } - DCHECK((reinterpret_cast<uintptr_t>(obj) & 0xffff0000) != 0xebad0000); + DCHECK_NE((reinterpret_cast<uintptr_t>(obj) & 0xffff0000), 0xebad0000); JNIEnvExt* env = reinterpret_cast<JNIEnvExt*>(public_env); IndirectReferenceTable& locals = env->locals; diff --git a/src/logging.h b/src/logging.h index 585cc6d1af..94dd2c6f1d 100644 --- a/src/logging.h +++ b/src/logging.h @@ -254,7 +254,7 @@ std::ostream& operator<<(std::ostream& os, const Dumpable<T>& rhs) { template<typename T> class ToStr { public: - ToStr(const T& value) { + explicit ToStr(const T& value) { std::ostringstream os; os << value; s_ = os.str(); diff --git a/src/mark_sweep.h b/src/mark_sweep.h index 43ed9b6b2d..7b0272c10d 100644 --- a/src/mark_sweep.h +++ b/src/mark_sweep.h @@ -30,7 +30,7 @@ class Object; class MarkSweep { public: - MarkSweep(MarkStack* mark_stack); + explicit MarkSweep(MarkStack* mark_stack); ~MarkSweep(); diff --git a/src/oat/jni/jni_compiler.cc b/src/oat/jni/jni_compiler.cc index 625580cd9a..49160726a9 100644 --- a/src/oat/jni/jni_compiler.cc +++ b/src/oat/jni/jni_compiler.cc @@ -179,7 +179,8 @@ static bool IsRegisterPair(InstructionSet instruction_set, ManagedRegister r) { CompiledMethod* ArtJniCompileMethodInternal(Compiler& compiler, uint32_t access_flags, uint32_t method_idx, const DexFile& dex_file) { - CHECK((access_flags & kAccNative) != 0); + const bool is_native = (access_flags & kAccNative) != 0; + CHECK(is_native); const bool is_static = (access_flags & kAccStatic) != 0; const bool is_synchronized = (access_flags & kAccSynchronized) != 0; const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); diff --git a/src/oat/runtime/oat_support_entrypoints.h b/src/oat/runtime/oat_support_entrypoints.h index edf5575ad6..a235e4fa71 100644 --- a/src/oat/runtime/oat_support_entrypoints.h +++ b/src/oat/runtime/oat_support_entrypoints.h @@ -20,8 +20,8 @@ #include "runtime.h" #define ENTRYPOINT_OFFSET(x) \ - (static_cast<uintptr_t>(OFFSETOF_MEMBER(Thread, entrypoints_)) + \ - static_cast<uintptr_t>(OFFSETOF_MEMBER(EntryPoints, x))) + (static_cast<uintptr_t>(OFFSETOF_MEMBER(Thread, entrypoints_)) + \ + static_cast<uintptr_t>(OFFSETOF_MEMBER(EntryPoints, x))) namespace art { diff --git a/src/oat/runtime/support_jni.cc b/src/oat/runtime/support_jni.cc index fb8b2e08f1..ff19a4c051 100644 --- a/src/oat/runtime/support_jni.cc +++ b/src/oat/runtime/support_jni.cc @@ -112,7 +112,7 @@ extern "C" const void* artWorkAroundAppJniBugs(Thread* self, intptr_t* sp) { arg_ptr = sp + 10; // skip to out arguments plus 2 slots as long must be aligned reg_num = -1; } else { - DCHECK(reg_num == -1); + DCHECK_EQ(reg_num, -1); if ((reinterpret_cast<intptr_t>(arg_ptr) & 7) == 4) { arg_ptr += 3; // unaligned, pad and move through stack arguments } else { @@ -127,7 +127,7 @@ extern "C" const void* artWorkAroundAppJniBugs(Thread* self, intptr_t* sp) { arg_ptr = sp + 8; // skip to outgoing stack arguments reg_num = -1; } else { - DCHECK(reg_num == -1); + DCHECK_EQ(reg_num, -1); arg_ptr++; // move through stack arguments } } diff --git a/src/oat/runtime/x86/stub_x86.cc b/src/oat/runtime/x86/stub_x86.cc index cd03455824..a9db314988 100644 --- a/src/oat/runtime/x86/stub_x86.cc +++ b/src/oat/runtime/x86/stub_x86.cc @@ -57,15 +57,15 @@ ByteArray* X86CreateResolutionTrampoline(Runtime::TrampolineType type) { __ popl(EBP); // Restore callee saves. __ popl(ESI); // Swap EDI callee save with code pointer - __ xchgl(EDI, Address(ESP,0)); + __ xchgl(EDI, Address(ESP, 0)); // Tail call to intended method. __ ret(); #else // ART_USE_LLVM_COMPILER __ pushl(EBP); __ movl(EBP, ESP); // save ESP __ subl(ESP, Immediate(8)); // Align stack - __ movl(EAX, Address(EBP,8)); // Method* called - __ leal(EDX, Address(EBP,8)); // Method** called_addr + __ movl(EAX, Address(EBP, 8)); // Method* called + __ leal(EDX, Address(EBP, 8)); // Method** called_addr __ pushl(Immediate(type)); // pass is_static __ fs()->pushl(Address::Absolute(Thread::SelfOffset())); // pass thread __ pushl(EDX); // pass called_addr @@ -132,7 +132,7 @@ ByteArray* CreateAbstractMethodErrorStub() { __ subl(ESP, Immediate(12)); // Align stack __ pushl(ESP); // pass sp (not use) __ fs()->pushl(Address::Absolute(Thread::SelfOffset())); // pass thread* - __ pushl(Address(EBP,8)); // pass method + __ pushl(Address(EBP, 8)); // pass method // Call to throw AbstractMethodError. __ Call(ThreadOffset(ENTRYPOINT_OFFSET(pThrowAbstractMethodErrorFromCode)), X86ManagedRegister::FromCpuRegister(ECX)); diff --git a/src/oat_file.cc b/src/oat_file.cc index 81e88ddf41..7762825d96 100644 --- a/src/oat_file.cc +++ b/src/oat_file.cc @@ -188,7 +188,7 @@ bool OatFile::Map(File& file, #else oat = map->Begin() + oat_header.GetElfImageTableOffset(); - CHECK((reinterpret_cast<uintptr_t>(oat) & 0x3) == 0); + CHECK_EQ((reinterpret_cast<uintptr_t>(oat) & 0x3), 0); for (uint32_t i = 0, end = oat_header.GetElfImageCount(); i < end; ++i) { uint32_t elf_offset = *reinterpret_cast<const uint32_t*>(oat); diff --git a/src/oat_writer.cc b/src/oat_writer.cc index d79e61b1ff..852320de9a 100644 --- a/src/oat_writer.cc +++ b/src/oat_writer.cc @@ -885,7 +885,7 @@ uint32_t OatWriter::OatElfImage::GetElfOffset() const { void OatWriter::OatElfImage::SetElfOffset(uint32_t offset) { DCHECK_NE(offset, 0U); - DCHECK((offset & 0x3LU) == 0); + DCHECK_EQ((offset & 0x3LU), 0U); elf_offset_ = offset; } diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc index 88a4a25acd..a84dfc9ae8 100644 --- a/src/runtime_linux.cc +++ b/src/runtime_linux.cc @@ -127,7 +127,7 @@ static const char* GetSignalCodeName(int signal_number, int signal_code) { } struct UContext { - UContext(void* raw_context) : context(reinterpret_cast<ucontext_t*>(raw_context)->uc_mcontext) {} + explicit UContext(void* raw_context) : context(reinterpret_cast<ucontext_t*>(raw_context)->uc_mcontext) {} void Dump(std::ostream& os) { // TODO: support non-x86 hosts (not urgent because this code doesn't run on targets). diff --git a/src/runtime_support.cc b/src/runtime_support.cc index 06908c996d..37be5f72e6 100644 --- a/src/runtime_support.cc +++ b/src/runtime_support.cc @@ -20,11 +20,11 @@ #include "well_known_classes.h" double art_l2d(int64_t l) { - return (double) l; + return static_cast<double>(l); } float art_l2f(int64_t l) { - return (float) l; + return static_cast<float>(l); } /* @@ -32,58 +32,58 @@ float art_l2f(int64_t l) { * target doesn't support this normally, use these. */ int64_t art_d2l(double d) { - static const double kMaxLong = (double) (int64_t) 0x7fffffffffffffffULL; - static const double kMinLong = (double) (int64_t) 0x8000000000000000ULL; + static const double kMaxLong = static_cast<double>(static_cast<int64_t>(0x7fffffffffffffffULL)); + static const double kMinLong = static_cast<double>(static_cast<int64_t>(0x8000000000000000ULL)); if (d >= kMaxLong) { - return (int64_t) 0x7fffffffffffffffULL; + return 0x7fffffffffffffffULL; } else if (d <= kMinLong) { - return (int64_t) 0x8000000000000000ULL; + return 0x8000000000000000ULL; } else if (d != d) { // NaN case return 0; } else { - return (int64_t) d; + return static_cast<int64_t>(d); } } int64_t art_f2l(float f) { - static const float kMaxLong = (float) (int64_t) 0x7fffffffffffffffULL; - static const float kMinLong = (float) (int64_t) 0x8000000000000000ULL; + static const float kMaxLong = static_cast<float>(static_cast<int64_t>(0x7fffffffffffffffULL)); + static const float kMinLong = static_cast<float>(static_cast<int64_t>(0x8000000000000000ULL)); if (f >= kMaxLong) { - return (int64_t) 0x7fffffffffffffffULL; + return 0x7fffffffffffffffULL; } else if (f <= kMinLong) { - return (int64_t) 0x8000000000000000ULL; + return 0x8000000000000000ULL; } else if (f != f) { // NaN case return 0; } else { - return (int64_t) f; + return static_cast<int64_t>(f); } } int32_t art_d2i(double d) { - static const double kMaxInt = (double) (int32_t) 0x7fffffffUL; - static const double kMinInt = (double) (int32_t) 0x80000000UL; + static const double kMaxInt = static_cast<double>(0x7fffffffUL); + static const double kMinInt = static_cast<double>(0x80000000UL); if (d >= kMaxInt) { - return (int32_t) 0x7fffffffUL; + return 0x7fffffffUL; } else if (d <= kMinInt) { - return (int32_t) 0x80000000UL; + return 0x80000000UL; } else if (d != d) { // NaN case return 0; } else { - return (int32_t) d; + return static_cast<int32_t>(d); } } int32_t art_f2i(float f) { - static const float kMaxInt = (float) (int32_t) 0x7fffffffUL; - static const float kMinInt = (float) (int32_t) 0x80000000UL; + static const float kMaxInt = static_cast<float>(0x7fffffffUL); + static const float kMinInt = static_cast<float>(0x80000000UL); if (f >= kMaxInt) { - return (int32_t) 0x7fffffffUL; + return 0x7fffffffUL; } else if (f <= kMinInt) { - return (int32_t) 0x80000000UL; + return 0x80000000UL; } else if (f != f) { // NaN case return 0; } else { - return (int32_t) f; + return static_cast<int32_t>(f); } } diff --git a/src/safe_map.h b/src/safe_map.h index 0af158fab1..6df05e2685 100644 --- a/src/safe_map.h +++ b/src/safe_map.h @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef ART_SRC_SAFE_MAP_H_ #define ART_SRC_SAFE_MAP_H_ @@ -20,7 +36,10 @@ class SafeMap { typedef typename ::std::map<K, V, Comparator>::size_type size_type; typedef typename ::std::map<K, V, Comparator>::value_type value_type; - Self& operator=(const Self& rhs) { map_ = rhs.map_; return *this; } + Self& operator=(const Self& rhs) { + map_ = rhs.map_; + return *this; + } iterator begin() { return map_.begin(); } const_iterator begin() const { return map_.begin(); } diff --git a/src/verifier/reg_type_cache.h b/src/verifier/reg_type_cache.h index 51eccd536b..ca0ada69ac 100644 --- a/src/verifier/reg_type_cache.h +++ b/src/verifier/reg_type_cache.h @@ -60,10 +60,10 @@ class RegTypeCache { const RegType& JavaLangString() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/String;"); } const RegType& JavaLangThrowable() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Throwable;"); } - const RegType& Undefined(){ return FromType(RegType::kRegTypeUndefined); } - const RegType& Conflict() { return FromType(RegType::kRegTypeConflict); } - const RegType& ConstLo() { return FromType(RegType::kRegTypeConstLo); } - const RegType& Zero() { return FromCat1Const(0); } + const RegType& Undefined() { return FromType(RegType::kRegTypeUndefined); } + const RegType& Conflict() { return FromType(RegType::kRegTypeConflict); } + const RegType& ConstLo() { return FromType(RegType::kRegTypeConstLo); } + const RegType& Zero() { return FromCat1Const(0); } const RegType& Uninitialized(const RegType& type, uint32_t allocation_pc); // Create an uninitialized 'this' argument for the given type. |