|
Lines 34-41
Link Here
|
| 34 |
#include <iostream> |
34 |
#include <iostream> |
| 35 |
#endif |
35 |
#endif |
| 36 |
|
36 |
|
| 37 |
static CInsSetJ InsSet; |
37 |
#include <assert.h> |
| 38 |
|
38 |
|
|
|
39 |
static CInsSetJ InsSet; |
| 39 |
//============================================================================== |
40 |
//============================================================================== |
| 40 |
// CModuleJ implementation |
41 |
// CModuleJ implementation |
| 41 |
//------------------------------------------------------------------------------ |
42 |
//------------------------------------------------------------------------------ |
|
Lines 51-56
CModuleJ::CModuleJ()
Link Here
|
| 51 |
m_fDestroyClass = false; |
52 |
m_fDestroyClass = false; |
| 52 |
m_fAccessFlags = 0; |
53 |
m_fAccessFlags = 0; |
| 53 |
m_sourceFileNamesPopulated = false; |
54 |
m_sourceFileNamesPopulated = false; |
|
|
55 |
m_verificationContext = NULL; |
| 56 |
m_classHandler = NULL; |
| 57 |
m_methodContexts = NULL; |
| 58 |
m_use_stack_map_recalculation = false; |
| 54 |
} |
59 |
} |
| 55 |
|
60 |
|
| 56 |
//------------------------------------------------------------------------------ |
61 |
//------------------------------------------------------------------------------ |
|
Lines 63-68
CModuleJ::~CModuleJ()
Link Here
|
| 63 |
{ |
68 |
{ |
| 64 |
delete m_pClass; |
69 |
delete m_pClass; |
| 65 |
} |
70 |
} |
|
|
71 |
if (m_verificationContext != NULL) { |
| 72 |
free_verification_context(m_verificationContext); |
| 73 |
m_verificationContext = NULL; |
| 74 |
} |
| 75 |
if (m_classHandler != NULL) { |
| 76 |
/*XXX: free here*/ |
| 77 |
m_classHandler = NULL; |
| 78 |
} |
| 79 |
if (m_methodContexts != NULL) { |
| 80 |
free(m_methodContexts); |
| 81 |
m_methodContexts = NULL; |
| 82 |
} |
| 66 |
} |
83 |
} |
| 67 |
|
84 |
|
| 68 |
//------------------------------------------------------------------------------ |
85 |
//------------------------------------------------------------------------------ |
|
Lines 83-88
CModuleJ::Open(CSTR i_szName)
Link Here
|
| 83 |
m_fDestroyClass = true; |
100 |
m_fDestroyClass = true; |
| 84 |
FileStreamIn.Close(); |
101 |
FileStreamIn.Close(); |
| 85 |
Verify(); |
102 |
Verify(); |
|
|
103 |
|
| 86 |
} |
104 |
} |
| 87 |
|
105 |
|
| 88 |
//------------------------------------------------------------------------------ |
106 |
//------------------------------------------------------------------------------ |
|
Lines 184-190
CModuleJ::CreateMethod(u2 i_u2AccFlags,
Link Here
|
| 184 |
} |
202 |
} |
| 185 |
|
203 |
|
| 186 |
//------------------------------------------------------------------------------ |
204 |
//------------------------------------------------------------------------------ |
| 187 |
void |
205 |
int |
| 188 |
CModuleJ::Parse() |
206 |
CModuleJ::Parse() |
| 189 |
{ |
207 |
{ |
| 190 |
CJMethods* pMethods = m_pClass->GetMethods(); |
208 |
CJMethods* pMethods = m_pClass->GetMethods(); |
|
Lines 227-238
CModuleJ::Parse()
Link Here
|
| 227 |
} |
245 |
} |
| 228 |
m_pMethods->push_back(pMtd); |
246 |
m_pMethods->push_back(pMtd); |
| 229 |
} |
247 |
} |
|
|
248 |
|
| 249 |
vf_Result status; |
| 250 |
int ind; |
| 251 |
if (GetClassBuilder().GetMajorVersion() >= 50 |
| 252 |
&& IsStackMapCalculationUsed()) { |
| 253 |
m_classHandler = get_class_handler_from_builder(this); |
| 254 |
assert(m_classHandler); |
| 255 |
m_verificationContext = allocate_verification_context(m_classHandler); |
| 256 |
assert(m_verificationContext); |
| 257 |
m_methodContexts = (method_handler *)malloc(m_pMethods->size() * sizeof(method_handler)); |
| 258 |
assert(m_methodContexts); |
| 259 |
memset(m_methodContexts, 0, m_pMethods->size() * sizeof(method_handler)); |
| 260 |
fprintf(stderr, "class : %s is java6 compiled\n", m_strName.c_str()); |
| 261 |
} |
| 230 |
|
262 |
|
| 231 |
CMethods::iterator iterm; |
263 |
CMethods::iterator iterm; |
| 232 |
for(iterm = m_pMethods->begin(); iterm < m_pMethods->end(); iterm++) |
264 |
for(iterm = m_pMethods->begin(), ind = 0; iterm < m_pMethods->end(); iterm++, ind++) |
| 233 |
{ |
265 |
{ |
| 234 |
(*iterm)->Parse(); |
266 |
(*iterm)->Parse(); |
|
|
267 |
if (GetClassBuilder().GetMajorVersion() >= 50 |
| 268 |
&& IsStackMapCalculationUsed()) { |
| 269 |
//malloc(5); |
| 270 |
m_methodContexts[ind] = get_method_handler_for_cmethod(*iterm); |
| 271 |
//malloc(50); |
| 272 |
assert(m_methodContexts[ind]); |
| 273 |
status = init_verification_context_for_method(m_methodContexts[ind], m_verificationContext); |
| 274 |
malloc(50); |
| 275 |
if (status != VF_OK) { |
| 276 |
fprintf(stderr, "class was skiped: %s\n", m_strName.c_str()); |
| 277 |
return (1); /*skip*/ |
| 278 |
} |
| 279 |
fprintf(stderr, "class was instrumented: %s\n", m_strName.c_str()); |
| 280 |
((CMethodJ *)(*iterm))->SetMethodHandler(m_methodContexts[ind]); |
| 281 |
} |
| 235 |
} |
282 |
} |
|
|
283 |
return (0); |
| 236 |
} |
284 |
} |
| 237 |
|
285 |
|
| 238 |
//------------------------------------------------------------------------------ |
286 |
//------------------------------------------------------------------------------ |
|
Lines 385-392
CMethodJ::Emit()
Link Here
|
| 385 |
m_pMtdExTable->Emit(); |
433 |
m_pMtdExTable->Emit(); |
| 386 |
|
434 |
|
| 387 |
//------- |
435 |
//------- |
| 388 |
// Loop over instructions and patch the local variable info table |
436 |
// Loop over instructions and patch the local variable info table, |
|
|
437 |
// local variable type table (Java 5.0) and stack map table (Java 6.0) |
| 389 |
// |
438 |
// |
|
|
439 |
|
| 440 |
|
| 390 |
|
441 |
|
| 391 |
// Local variable table LVT |
442 |
// Local variable table LVT |
| 392 |
CLocalVariableTableAttribute* pLclAttr = m_pCodeAttr->GetLocalVariables(); |
443 |
CLocalVariableTableAttribute* pLclAttr = m_pCodeAttr->GetLocalVariables(); |
|
Lines 403-408
CMethodJ::Emit()
Link Here
|
| 403 |
CLocalVariableTypeTable LclTypeTableSav; |
454 |
CLocalVariableTypeTable LclTypeTableSav; |
| 404 |
CLocalVariableTypeTable::iterator itrLclType, itrLclTypeSav; // LVTT Iterator |
455 |
CLocalVariableTypeTable::iterator itrLclType, itrLclTypeSav; // LVTT Iterator |
| 405 |
|
456 |
|
|
|
457 |
// The smtNull variable is for reference initialization in case the method does not have |
| 458 |
// a Stack Map Table attribute |
| 459 |
CStackMapTable smtNull; |
| 460 |
CStackMapTableAttribute* pSmtAttr = m_pCodeAttr->GetStackMaps(); |
| 461 |
CStackMapTable& StackMapTable = pSmtAttr?pSmtAttr->GetStackMapTable():smtNull; |
| 462 |
CStackMapTable::iterator itrStackMapFrame = StackMapTable.begin(); |
| 463 |
|
| 406 |
CInsBlocks::iterator iterBlocks; |
464 |
CInsBlocks::iterator iterBlocks; |
| 407 |
IP_t ip = 0; |
465 |
IP_t ip = 0; |
| 408 |
|
466 |
|
|
Lines 458-463
CMethodJ::Emit()
Link Here
|
| 458 |
} |
516 |
} |
| 459 |
} |
517 |
} |
| 460 |
} |
518 |
} |
|
|
519 |
|
| 520 |
// Scan for a relevant entry in the Stack Map Table and fix it |
| 521 |
while (itrStackMapFrame != StackMapTable.end() |
| 522 |
&& (*itrStackMapFrame)->GetByteCodeOffset() < ipOrig) |
| 523 |
{ |
| 524 |
++itrStackMapFrame; |
| 525 |
} |
| 526 |
if (itrStackMapFrame != StackMapTable.end() |
| 527 |
&& (*itrStackMapFrame)->GetByteCodeOffset() == ipOrig) |
| 528 |
{ |
| 529 |
(*itrStackMapFrame)->SetByteCodeOffset(ip); |
| 530 |
} |
| 461 |
|
531 |
|
| 462 |
// Advance ip |
532 |
// Advance ip |
| 463 |
ip += (*iterIns)->GetSize(ip); |
533 |
ip += (*iterIns)->GetSize(ip); |
|
Lines 503-513
CMethodJ::Emit()
Link Here
|
| 503 |
} |
573 |
} |
| 504 |
} |
574 |
} |
| 505 |
} |
575 |
} |
|
|
576 |
// Replace the method body |
| 577 |
m_pCodeAttr->SetCode(m_pBody->GetCodeSize(), m_pBody->GiveAvayCode()); |
| 506 |
|
578 |
|
|
|
579 |
// Calculate new stack depth |
| 507 |
CalcStackDepth(); |
580 |
CalcStackDepth(); |
| 508 |
|
581 |
|
| 509 |
// Replace the method body |
582 |
if (((CModuleJ *)GetModule())->GetClassBuilder().GetMajorVersion() >= 50 |
| 510 |
m_pCodeAttr->SetCode(m_pBody->GetCodeSize(), m_pBody->GiveAvayCode()); |
583 |
&& ((CModuleJ *)GetModule())->IsStackMapCalculationUsed()) { |
|
|
584 |
|
| 585 |
u1 *tbl; |
| 586 |
vf_Result status; |
| 587 |
status = recompute_stackmaptable((uint8 **)&tbl, m_methodHandler, ((CModuleJ *)GetModule())->GetVerificationContext()); |
| 588 |
if (status != VF_OK) { |
| 589 |
__asm {int 3} |
| 590 |
} |
| 591 |
else { |
| 592 |
//CStackMapTable smt (tbl); |
| 593 |
CStackMapTableAttribute* smta = GetCodeAttribute()->GetOrCreateStackMaps(); |
| 594 |
if (tbl != NULL) { |
| 595 |
smta->RereadFromBuffer(tbl); //skiping name |
| 596 |
smta->GetStackMapTable().AdjustOffsetDeltas(); |
| 597 |
} |
| 598 |
} |
| 599 |
} |
| 600 |
// Final Stack Map Table handling: adjust offset deltas |
| 601 |
//StackMapTable.AdjustOffsetDeltas(); |
| 602 |
|
| 603 |
|
| 604 |
|
| 511 |
|
605 |
|
| 512 |
} |
606 |
} |
| 513 |
|
607 |
|
|
Lines 623-633
CMtdExTableJ::Emit()
Link Here
|
| 623 |
{ |
717 |
{ |
| 624 |
ipRealEnd = ipIns + pi->GetSize(); |
718 |
ipRealEnd = ipIns + pi->GetSize(); |
| 625 |
bDone = true; |
719 |
bDone = true; |
|
|
720 |
//assert(ipStart != ipRealEnd); |
| 721 |
//(*itrEx)->SetStart(ipStart); |
| 722 |
//(*itrEx)->SetEnd(ipRealEnd); |
| 626 |
break; |
723 |
break; |
| 627 |
} |
724 |
} |
| 628 |
} |
725 |
} |
| 629 |
} |
726 |
} |
| 630 |
} |
727 |
} |
|
|
728 |
|
| 631 |
CJException jex = CJException(uType, ipStart, ipRealEnd, ipHandler); |
729 |
CJException jex = CJException(uType, ipStart, ipRealEnd, ipHandler); |
| 632 |
extblj.push_back(jex); |
730 |
extblj.push_back(jex); |
| 633 |
} |
731 |
} |