Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 148629 | Differences between
and this patch

Collapse All | Expand All

(-)src-native/BCI/BCIEng/BCIEng.dsp (-1 / +3 lines)
Lines 23-28 CFG=BCIEng - Win32 Debug Link Here
23
23
24
# Begin Project
24
# Begin Project
25
# PROP AllowPerConfigDependencies 0
25
# PROP AllowPerConfigDependencies 0
26
# PROP Scc_ProjName ""
27
# PROP Scc_LocalPath ""
26
CPP=cl.exe
28
CPP=cl.exe
27
RSC=rc.exe
29
RSC=rc.exe
28
30
Lines 62-68 LIB32=link.exe -lib Link Here
62
# PROP Intermediate_Dir "Debug"
64
# PROP Intermediate_Dir "Debug"
63
# PROP Target_Dir ""
65
# PROP Target_Dir ""
64
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
66
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
65
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\Common" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
67
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\Common" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
66
# ADD BASE RSC /l 0x409 /d "_DEBUG"
68
# ADD BASE RSC /l 0x409 /d "_DEBUG"
67
# ADD RSC /l 0x409 /d "_DEBUG"
69
# ADD RSC /l 0x409 /d "_DEBUG"
68
BSC32=bscmake.exe
70
BSC32=bscmake.exe
(-)src-native/BCI/BCIEng/BCIEng.dsw (-8 / +8 lines)
Lines 3-9 Microsoft Developer Studio Workspace Fil Link Here
3
3
4
###############################################################################
4
###############################################################################
5
5
6
Project: "BCIEng"=.\BCIEng.dsp - Package Owner=<4>
6
Project: "BCIEng"=".\BCIEng.dsp" - Package Owner=<4>
7
7
8
Package=<5>
8
Package=<5>
9
{{{
9
{{{
Lines 15-21 Package=<4> Link Here
15
15
16
###############################################################################
16
###############################################################################
17
17
18
Project: "BCIEngJ"=.\BCIEngJ\BCIEngJ.dsp - Package Owner=<4>
18
Project: "BCIEngJ"=".\BCIEngJ\BCIEngJ.dsp" - Package Owner=<4>
19
19
20
Package=<5>
20
Package=<5>
21
{{{
21
{{{
Lines 30-36 Package=<4> Link Here
30
30
31
###############################################################################
31
###############################################################################
32
32
33
Project: "BCIEngProbe"=.\BCIEngProbe\BCIEngProbe.dsp - Package Owner=<4>
33
Project: "BCIEngProbe"=".\BCIEngProbe\BCIEngProbe.dsp" - Package Owner=<4>
34
34
35
Package=<5>
35
Package=<5>
36
{{{
36
{{{
Lines 48-54 Package=<4> Link Here
48
48
49
###############################################################################
49
###############################################################################
50
50
51
Project: "BciEngJTest"=.\BCIEngJ\BciEngJTest\BciEngJTest.dsp - Package Owner=<4>
51
Project: "BciEngJTest"=".\BCIEngJ\BciEngJTest\BciEngJTest.dsp" - Package Owner=<4>
52
52
53
Package=<5>
53
Package=<5>
54
{{{
54
{{{
Lines 60-66 Package=<4> Link Here
60
60
61
###############################################################################
61
###############################################################################
62
62
63
Project: "JClassStat"=..\JClass\JClassStat.dsp - Package Owner=<4>
63
Project: "JClassStat"="..\JClass\JClassStat.dsp" - Package Owner=<4>
64
64
65
Package=<5>
65
Package=<5>
66
{{{
66
{{{
Lines 72-78 Package=<4> Link Here
72
72
73
###############################################################################
73
###############################################################################
74
74
75
Project: "JDump"=..\JDump\JDump.dsp - Package Owner=<4>
75
Project: "JDump"="..\JDump\JDump.dsp" - Package Owner=<4>
76
76
77
Package=<5>
77
Package=<5>
78
{{{
78
{{{
Lines 90-96 Package=<4> Link Here
90
90
91
###############################################################################
91
###############################################################################
92
92
93
Project: "ProbeInstrumenter"=.\BCIEngProbe\ProbeInstrumenter\ProbeInstrumenter.dsp - Package Owner=<4>
93
Project: "ProbeInstrumenter"=".\BCIEngProbe\ProbeInstrumenter\ProbeInstrumenter.dsp" - Package Owner=<4>
94
94
95
Package=<5>
95
Package=<5>
96
{{{
96
{{{
Lines 105-111 Package=<4> Link Here
105
105
106
###############################################################################
106
###############################################################################
107
107
108
Project: "ProbeUnitTests"=.\ProbeUnitTests\ProbeUnitTests.dsp - Package Owner=<4>
108
Project: "ProbeUnitTests"=".\ProbeUnitTests\ProbeUnitTests.dsp" - Package Owner=<4>
109
109
110
Package=<5>
110
Package=<5>
111
{{{
111
{{{
(-)src-native/BCI/BCIEng/BCIEngInterface.h (+2 lines)
Lines 152-157 typedef void* pbcieng_t; Link Here
152
	_BCIENGINTERFACE_EXT_REF unsigned Initialize(pbcieng_t i_pbcieng, const char* i_pchOptions, size_t i_cbOptions);
152
	_BCIENGINTERFACE_EXT_REF unsigned Initialize(pbcieng_t i_pbcieng, const char* i_pchOptions, size_t i_cbOptions);
153
	_BCIENGINTERFACE_EXT_REF unsigned Instrument(pbcieng_t i_pbcieng, void* i_pInClass, size_t i_cbInClass, 
153
	_BCIENGINTERFACE_EXT_REF unsigned Instrument(pbcieng_t i_pbcieng, void* i_pInClass, size_t i_cbInClass, 
154
							          void** o_ppOutClass, size_t* o_pcbOutClass);
154
							          void** o_ppOutClass, size_t* o_pcbOutClass);
155
	_BCIENGINTERFACE_EXT_REF unsigned Instrument2(pbcieng_t i_pbcieng, void* i_pInClass, size_t i_cbInClass, 
156
							          void** o_ppOutClass, size_t* o_pcbOutClass, void *(*)(void **));
155
	_BCIENGINTERFACE_EXT_REF unsigned SetAllocator(pbcieng_t i_pbcieng, pfnMalloc_t i_pfnMalloc);
157
	_BCIENGINTERFACE_EXT_REF unsigned SetAllocator(pbcieng_t i_pbcieng, pfnMalloc_t i_pfnMalloc);
156
	_BCIENGINTERFACE_EXT_REF unsigned SetCallback(pbcieng_t i_pbcieng, pfnCallback_t i_pfnCallback, unsigned i_uFlags);
158
	_BCIENGINTERFACE_EXT_REF unsigned SetCallback(pbcieng_t i_pbcieng, pfnCallback_t i_pfnCallback, unsigned i_uFlags);
157
159
(-)src-native/BCI/BCIEng/Module.h (-1 / +1 lines)
Lines 132-138 public: Link Here
132
132
133
	virtual const vector<string>& GetSourceFileNames() = 0;
133
	virtual const vector<string>& GetSourceFileNames() = 0;
134
134
135
	virtual void	Parse()=0;
135
	virtual int	Parse()=0;
136
	virtual void	Emit();
136
	virtual void	Emit();
137
137
138
	CMethods*		GetMethods(){return m_pMethods;}
138
	CMethods*		GetMethods(){return m_pMethods;}
(-)src-native/BCI/BCIEng/BCIEngJ/BCIEngJ.dsp (-2 / +15 lines)
Lines 41-47 RSC=rc.exe Link Here
41
# PROP Intermediate_Dir "Release"
41
# PROP Intermediate_Dir "Release"
42
# PROP Target_Dir ""
42
# PROP Target_Dir ""
43
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
43
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
44
# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /I "..\\" /I "..\..\jclass" /I "..\..\..\sun" /I "..\..\common" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
44
# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /I "..\..\common" /I "${JAVA_HOME}\include" /I "${JAVA_HOME}\include\win32" /I "${HARMONY_VERIFIER}\open\include" /I "${HARMONY_VERIFIER}\verifier-3363\x_verifier" /I "%HARMONY_VERIFIER%\include" /I "..\..\Common" /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "..\\" /I "..\..\jclass" /I "..\..\..\sun" /I "..\..\..\..\..\org.apache.harmony_vmcore_verifier\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
45
# ADD BASE RSC /l 0x409 /d "NDEBUG"
45
# ADD BASE RSC /l 0x409 /d "NDEBUG"
46
# ADD RSC /l 0x409 /d "NDEBUG"
46
# ADD RSC /l 0x409 /d "NDEBUG"
47
BSC32=bscmake.exe
47
BSC32=bscmake.exe
Lines 64-70 LIB32=link.exe -lib Link Here
64
# PROP Intermediate_Dir "Debug"
64
# PROP Intermediate_Dir "Debug"
65
# PROP Target_Dir ""
65
# PROP Target_Dir ""
66
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
66
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
67
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Common" /I "..\\" /I "..\..\jclass" /I "..\..\..\sun" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
67
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Common" /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "..\\" /I "..\..\jclass" /I "..\..\..\sun" /I "..\..\..\..\..\org.apache.harmony_vmcore_verifier\include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /FR /FD /GZ /c
68
# SUBTRACT CPP /YX
68
# ADD BASE RSC /l 0x409 /d "_DEBUG"
69
# ADD BASE RSC /l 0x409 /d "_DEBUG"
69
# ADD RSC /l 0x409 /d "_DEBUG"
70
# ADD RSC /l 0x409 /d "_DEBUG"
70
BSC32=bscmake.exe
71
BSC32=bscmake.exe
Lines 85-90 LIB32=link.exe -lib Link Here
85
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
86
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
86
# Begin Source File
87
# Begin Source File
87
88
89
SOURCE=.\class_interface.cpp
90
# End Source File
91
# Begin Source File
92
88
SOURCE=.\ExtRefJ_Interface.cpp
93
SOURCE=.\ExtRefJ_Interface.cpp
89
# End Source File
94
# End Source File
90
# Begin Source File
95
# Begin Source File
Lines 105-110 SOURCE=.\ModuleJ.cpp Link Here
105
# PROP Default_Filter "h;hpp;hxx;hm;inl"
110
# PROP Default_Filter "h;hpp;hxx;hm;inl"
106
# Begin Source File
111
# Begin Source File
107
112
113
SOURCE=.\class_inerface_int.h
114
# End Source File
115
# Begin Source File
116
117
SOURCE=.\class_interface_x.h
118
# End Source File
119
# Begin Source File
120
108
SOURCE=.\ExtRefJ_Interface.h
121
SOURCE=.\ExtRefJ_Interface.h
109
# End Source File
122
# End Source File
110
# Begin Source File
123
# Begin Source File
(-)src-native/BCI/BCIEng/BCIEngJ/ModuleJ.cpp (-6 / +99 lines)
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
		free(m_classHandler);
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
			m_methodContexts[ind] = get_method_handler_for_cmethod(*iterm);
270
			assert(m_methodContexts[ind]);
271
			status = init_verification_context_for_method(m_methodContexts[ind], m_verificationContext);
272
			malloc(50);
273
			if (status != VF_OK) {
274
				fprintf(stderr, "class was skiped: %s\n", m_strName.c_str());
275
				return (1); /*skip*/
276
			}
277
			fprintf(stderr, "class was instrumented: %s\n", m_strName.c_str());
278
			((CMethodJ *)(*iterm))->SetMethodHandler(m_methodContexts[ind]);
279
		}
235
	}
280
	}
281
	return (0);
236
}
282
}
237
283
238
//------------------------------------------------------------------------------
284
//------------------------------------------------------------------------------
Lines 385-392 CMethodJ::Emit() Link Here
385
	m_pMtdExTable->Emit();
431
	m_pMtdExTable->Emit();
386
432
387
	//-------
433
	//-------
388
	// Loop over instructions and patch the local variable info table
434
	// Loop over instructions and patch the local variable info table, 
435
    // local variable type table (Java 5.0) and stack map table (Java 6.0)
389
	//
436
	//
437
	
438
	
390
439
391
	// Local variable table LVT
440
	// Local variable table LVT
392
	CLocalVariableTableAttribute* pLclAttr = m_pCodeAttr->GetLocalVariables();
441
	CLocalVariableTableAttribute* pLclAttr = m_pCodeAttr->GetLocalVariables();
Lines 403-408 CMethodJ::Emit() Link Here
403
	CLocalVariableTypeTable  LclTypeTableSav;
452
	CLocalVariableTypeTable  LclTypeTableSav;
404
	CLocalVariableTypeTable::iterator itrLclType, itrLclTypeSav; // LVTT Iterator
453
	CLocalVariableTypeTable::iterator itrLclType, itrLclTypeSav; // LVTT Iterator
405
454
455
    // The smtNull variable is for reference initialization in case the method does not have
456
    // a Stack Map Table attribute
457
    CStackMapTable smtNull;
458
    CStackMapTableAttribute* pSmtAttr = m_pCodeAttr->GetStackMaps();
459
    CStackMapTable& StackMapTable = pSmtAttr?pSmtAttr->GetStackMapTable():smtNull;
460
    CStackMapTable::iterator itrStackMapFrame = StackMapTable.begin();
461
406
	CInsBlocks::iterator iterBlocks;
462
	CInsBlocks::iterator iterBlocks;
407
	IP_t ip = 0;
463
	IP_t ip = 0;
408
464
Lines 458-463 CMethodJ::Emit() Link Here
458
					}
514
					}
459
				}
515
				}
460
			}
516
			}
517
			
518
            // Scan for a relevant entry in the Stack Map Table and fix it
519
            while (itrStackMapFrame != StackMapTable.end()
520
                && (*itrStackMapFrame)->GetByteCodeOffset() < ipOrig)
521
            {
522
                ++itrStackMapFrame;
523
            }
524
            if (itrStackMapFrame != StackMapTable.end()
525
                && (*itrStackMapFrame)->GetByteCodeOffset() == ipOrig)
526
            {
527
                (*itrStackMapFrame)->SetByteCodeOffset(ip);
528
            }
461
529
462
			// Advance ip
530
			// Advance ip
463
			ip += (*iterIns)->GetSize(ip);
531
			ip += (*iterIns)->GetSize(ip);
Lines 503-513 CMethodJ::Emit() Link Here
503
			}
571
			}
504
		}
572
		}
505
	}
573
	}
574
	// Replace the method body
575
	m_pCodeAttr->SetCode(m_pBody->GetCodeSize(), m_pBody->GiveAvayCode());
506
576
577
	// Calculate new stack depth
507
	CalcStackDepth();
578
	CalcStackDepth();
508
579
509
	// Replace the method body
580
	if (((CModuleJ *)GetModule())->GetClassBuilder().GetMajorVersion() >= 50 
510
	m_pCodeAttr->SetCode(m_pBody->GetCodeSize(), m_pBody->GiveAvayCode());
581
		&& ((CModuleJ *)GetModule())->IsStackMapCalculationUsed()) {
582
	
583
		u1 *tbl;
584
		vf_Result status;
585
		status = recompute_stackmaptable((uint8 **)&tbl, m_methodHandler, ((CModuleJ *)GetModule())->GetVerificationContext());
586
		if (status != VF_OK) {
587
			assert(!"verification failed");
588
		}
589
		else {
590
			//CStackMapTable smt (tbl);
591
			CStackMapTableAttribute* smta = GetCodeAttribute()->GetOrCreateStackMaps();
592
			if (tbl != NULL) {
593
				smta->RereadFromBuffer(tbl); //skiping name
594
				smta->GetStackMapTable().AdjustOffsetDeltas();
595
			}
596
		}
597
	}
598
    // Final Stack Map Table handling: adjust offset deltas
599
    //StackMapTable.AdjustOffsetDeltas();
600
601
    
602
511
603
512
}
604
}
513
605
Lines 628-633 CMtdExTableJ::Emit() Link Here
628
				}
720
				}
629
			}
721
			}
630
		}
722
		}
723
		
631
		CJException jex = CJException(uType, ipStart, ipRealEnd, ipHandler); 
724
		CJException jex = CJException(uType, ipStart, ipRealEnd, ipHandler); 
632
		extblj.push_back(jex);
725
		extblj.push_back(jex);
633
	}
726
	}
(-)src-native/BCI/BCIEng/BCIEngJ/ModuleJ.h (-2 / +14 lines)
Lines 30-35 Link Here
30
30
31
#include "Module.h"
31
#include "Module.h"
32
#include "JClassBuilder.h"
32
#include "JClassBuilder.h"
33
#include "class_inerface_int.h"
33
34
34
class CModuleJ;
35
class CModuleJ;
35
class CMethodJ;
36
class CMethodJ;
Lines 57-75 public: Link Here
57
	virtual void	Open(CJClassBuilder* io_pClass, bool i_fDestroyClass = false);
58
	virtual void	Open(CJClassBuilder* io_pClass, bool i_fDestroyClass = false);
58
	virtual void	AddExtRef(CExtRef& i_ExtRef);
59
	virtual void	AddExtRef(CExtRef& i_ExtRef);
59
	virtual void	AddStringAttrib(CSTR i_szName, CSTR i_szValue);
60
	virtual void	AddStringAttrib(CSTR i_szName, CSTR i_szValue);
60
	virtual void	Parse();
61
	virtual int	Parse();
61
	virtual void	Emit();
62
	virtual void	Emit();
62
63
63
	void	Emit(CJStream& i_jstream);	// Java specific emission
64
	void	Emit(CJStream& i_jstream);	// Java specific emission
64
	CJClassFile&	GetClass();
65
	CJClassFile&	GetClass();
65
	CJClassBuilder& GetClassBuilder();
66
	CJClassBuilder& GetClassBuilder();
67
	class_handler GetClassHandler() {return m_classHandler;}
68
	verification_context GetVerificationContext(){return m_verificationContext;}
66
69
67
	virtual const vector<string>& GetSourceFileNames();
70
	virtual const vector<string>& GetSourceFileNames();
68
71
69
	// Module modification methods
72
	// Module modification methods
70
	CCPFieldrefInfo*	CreateFieldRef(u2 i_u2AccFlags, CSTR i_szName, CJavaType i_jtype);
73
	CCPFieldrefInfo*	CreateFieldRef(u2 i_u2AccFlags, CSTR i_szName, CJavaType i_jtype);
71
	CMethodJ*			CreateMethod(u2 i_u2AccFlags, CSTR i_szName, CSTR i_szSignature);
74
	CMethodJ*			CreateMethod(u2 i_u2AccFlags, CSTR i_szName, CSTR i_szSignature);
72
75
	bool IsStackMapCalculationUsed() const {return m_use_stack_map_recalculation;}
76
	void UseStackMapCalculation(bool a_use_stack_map_recalculation) {m_use_stack_map_recalculation = a_use_stack_map_recalculation;}
73
protected:
77
protected:
74
78
75
private:
79
private:
Lines 85-90 private: Link Here
85
	// Storage in support of GetSourceFileNames:
89
	// Storage in support of GetSourceFileNames:
86
	vector<string>	m_sourceFileNames;
90
	vector<string>	m_sourceFileNames;
87
	bool			m_sourceFileNamesPopulated;
91
	bool			m_sourceFileNamesPopulated;
92
	verification_context m_verificationContext; /*verifier context for support java 6.0 and latter*/
93
	class_handler m_classHandler; /* class descriptor used for verification needs(recalculations) introduced in java 6.0*/
94
	method_handler *m_methodContexts; /*collections of method handlers*/
95
	bool m_use_stack_map_recalculation;
88
};
96
};
89
97
90
//==============================================================================
98
//==============================================================================
Lines 100-105 public: Link Here
100
		m_strSignature = i_szSignature;
108
		m_strSignature = i_szSignature;
101
		m_pCodeAttr = i_pCodeAttr;
109
		m_pCodeAttr = i_pCodeAttr;
102
		m_u2AccessFlags = i_u2AccessFlags;
110
		m_u2AccessFlags = i_u2AccessFlags;
111
		
103
112
104
		// Set the "hasThis" attribute, which is accessible to all CMethod users
113
		// Set the "hasThis" attribute, which is accessible to all CMethod users
105
		SetHasThis(!(m_u2AccessFlags & ACC_STATIC));
114
		SetHasThis(!(m_u2AccessFlags & ACC_STATIC));
Lines 110-115 public: Link Here
110
	CSTR	GetSignature() const {return m_strSignature.c_str();}
119
	CSTR	GetSignature() const {return m_strSignature.c_str();}
111
	bool IsAbstract() { return ((m_u2AccessFlags & ACC_ABSTRACT) != 0); };
120
	bool IsAbstract() { return ((m_u2AccessFlags & ACC_ABSTRACT) != 0); };
112
    u2 GetAccessFlags() const { return m_u2AccessFlags; }
121
    u2 GetAccessFlags() const { return m_u2AccessFlags; }
122
	void SetMethodHandler(method_handler i_methodHandler) {m_methodHandler = i_methodHandler;}
123
	method_handler GetMethodHandler() {return m_methodHandler;}
113
124
114
	virtual void Parse();
125
	virtual void Parse();
115
	virtual void Emit();
126
	virtual void Emit();
Lines 121-126 private: Link Here
121
	CCodeAttribute*		m_pCodeAttr;		// Code attribute from CJClassFile
132
	CCodeAttribute*		m_pCodeAttr;		// Code attribute from CJClassFile
122
	u2					m_u2AccessFlags;	// Method access flags
133
	u2					m_u2AccessFlags;	// Method access flags
123
	IP_t				m_origCodeLength;	// Saved code length from Parse to Emit
134
	IP_t				m_origCodeLength;	// Saved code length from Parse to Emit
135
	method_handler		m_methodHandler;
124
};
136
};
125
137
126
138
(-)src-native/BCI/BCIEng/BCIEngJ/class_inerface_int.h (+41 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html         
7
 * $Id$ 
8
 * 
9
 * Contributors: 
10
 * Intel - Initial API and implementation 
11
 **********************************************************************/ 
12
13
#ifndef _CLASS_INTERFACE_INT_H_
14
#define _CLASS_INTERFACE_INT_H_
15
16
#include "JClassBuilder.h"
17
18
//typedef u1 uint8;
19
//typedef u2 uint16;
20
//#include "class_interface.h"
21
//#include "class_interface_x.h"
22
23
#include "verifier-ext/x_class_interface.h"
24
#include "verifier-ext/x_verifier.h"
25
26
typedef Class_Handle class_handler;
27
typedef Method_Handle method_handler;
28
typedef void *(*get_vm_pointer_t)(void **);
29
30
class_handler get_class_handler_from_builder(class CModuleJ *);
31
method_handler get_method_handler_for_cmethod(class CMethod *);
32
33
//extern "C" {
34
//unsigned method_get_bytecode_length( method_handler);
35
//}
36
37
extern int initialize_dynamic(get_vm_pointer_t);
38
39
int initialize_static();
40
41
#endif
(-)src-native/BCI/BCIEng/BCIEngJ/class_interface.cpp (+1225 lines)
Added Link Here
1
#include <stdlib.h>
2
#include <string.h>
3
4
#include <map>
5
6
#include <assert.h>
7
#include "BCIEng.h"
8
#include "JClassBuilder.h"
9
#include "ModuleJ.h"
10
11
#include "JMemStream.h"
12
#include "class_inerface_int.h"
13
14
15
#include <jni.h>
16
17
typedef unsigned long intptr;
18
19
static JNIEnv *(*m_get_vm_pointer)(void **);
20
21
static jclass m_j_l_class;
22
static jclass m_j_l_classloader;
23
static jmethodID m_j_l_class_getName; /*()Ljava/lang/String;*/
24
static jmethodID m_j_l_class_isInterface;/* ()Z */
25
static jmethodID m_j_l_class_getClassLoader; /*()Ljava/lang/ClassLoader;*/
26
static jmethodID m_j_l_classloader_findLoadedClass; /*(Ljava/lang/String;)Ljava/lang/Class;*/
27
static jmethodID m_j_l_classloader_getSystemClassLoader; /*()Ljava/lang/ClassLoader;*/
28
static jobject m_system_classloader;
29
/**
30
 * Define class handler
31
 */
32
/*[0xdead0001 - simplefied, 0xdead0002 - instrumented, 0xdead0000 - none]*/
33
#define CLASS_HANDLER_MASK 0xdeadffff
34
#define CLASS_HANDLER_SIMPLEFIED 0xdead0001
35
#define CLASS_HANDLER_INSTRUMENTED 0xdead0002
36
#define CLASS_HANDLER_NONE 0xdead0000
37
#define IS_CLASS_INSTRUMENTED(x) (((x)->magic & CLASS_HANDLER_MASK) == CLASS_HANDLER_INSTRUMENTED)
38
struct Class{
39
	int magic; 
40
	struct {
41
		class CModuleJ *instrumented_class;
42
		void *simplefied_class;
43
	} X; /*XXX: possible union here will be more applieble */
44
	int loaded;
45
	const char *class_name; /*used if loaded = 0*/
46
	struct Class *super_class;
47
};
48
49
typedef std::map<std::string,class_handler> name2ch_t;
50
static name2ch_t m_name2ch;
51
52
#define MEHTOD_HANDLER_MASK 0xbabeffff
53
#define METHOD_HANDLER_SELF 0xbabe0001
54
#define METHOD_HANDLER_EXT 0xbabe0002
55
#define METHOD_HANDLER_NONE 0xbabe0000
56
struct Method {
57
	int magic; 
58
	struct {
59
		class CMethodJ *instrumented_method;
60
		void *simplefied_method;
61
	} X; /*XXX: possible union here will be more applieble */
62
	class_handler class_owner;
63
	const char *method_name; /*used for METHOD_HANDLER_EXT only*/
64
	const char *method_descriptor; /*used for METHOD_HANDLER_EXT only*/
65
};
66
67
static struct Class *m_j_l_object_ch; 
68
/**
69
 * Define field handler
70
 */
71
typedef struct Field_ * field_handler;
72
73
/**
74
 * Define method handler
75
 */
76
//typedef struct Method_ * method_handler;
77
78
/**
79
 * Define class loader handler
80
 */
81
typedef struct ClassLoader_ * classloader_handler;
82
83
static int 
84
create_class_handler(class_handler *pch, int flag, const char *class_name, int loaded, void *dsk)
85
{
86
	class_handler ch0 = m_name2ch[class_name]; /*for debug*/
87
	if (m_name2ch[class_name] != NULL 
88
		&& m_name2ch[class_name]->magic == flag) {
89
			*pch = m_name2ch[class_name];
90
			return (0);
91
	} 
92
	class_handler ch = (class_handler)malloc(sizeof(struct Class));
93
	memset(ch, 0, sizeof(struct Class));
94
	assert(ch);
95
	ch->loaded = loaded;
96
	if (loaded == 0) {
97
		ch->class_name = class_name;
98
	}
99
	ch->magic = flag;
100
	switch(flag) {
101
	case (CLASS_HANDLER_SIMPLEFIED):
102
		ch->X.simplefied_class = dsk;
103
		if (loaded == 0) {
104
			ch->class_name = class_name;
105
		}
106
		ch->loaded = loaded;
107
		break;
108
	case (CLASS_HANDLER_INSTRUMENTED):
109
		ch->X.instrumented_class = (CModuleJ *)dsk;
110
		break;
111
	default:
112
		assert(!"shouldn't be here!!!");
113
	}
114
	*pch = ch;
115
	m_name2ch[class_name] = ch;
116
	return (0);
117
}
118
119
extern "C" int
120
create_method_handler(method_handler *pmh, class_handler ch, int flag, void *dsk) 
121
{
122
	method_handler mh = (method_handler)malloc(sizeof(struct Method));
123
	assert(mh);
124
	memset(mh, 0, sizeof(struct Method));
125
	switch (flag) {
126
	case METHOD_HANDLER_SELF:
127
		mh->X.instrumented_method = (class CMethodJ *)dsk;
128
		break;
129
	case METHOD_HANDLER_EXT:
130
		mh->X.simplefied_method = dsk;
131
		break;
132
	default:
133
		assert(!"shouldn't enter here");
134
	}
135
	mh->magic = (IS_CLASS_INSTRUMENTED(ch))?METHOD_HANDLER_SELF:flag;
136
	mh->class_owner = ch;
137
	*pmh = mh;
138
	return (0);
139
}
140
/**
141
 * Class interface
142
 */
143
144
/**
145
 * Function returns class major version.
146
 * @param klass - class handler
147
 * @return Class name bytes.
148
 * @note Assertion is raised if klass is equal to null.
149
 */
150
extern "C" unsigned short 
151
class_get_version( class_handler klass ) {
152
	if (IS_CLASS_INSTRUMENTED(klass)) {
153
		return klass->X.instrumented_class->GetClassBuilder().GetMajorVersion();
154
	} else {
155
		assert (!"not implemented yet!");
156
	}
157
	return (0);
158
}
159
160
/** 
161
 * Function returns class name.
162
 * @param klass - class handler
163
 * @return Class name bytes.
164
 * @note Assertion is raised if klass is equal to null.
165
 */
166
extern "C" const char *
167
class_get_name( class_handler klass ) 
168
{
169
	JNIEnv *env;
170
	jstring class_name;
171
	if (IS_CLASS_INSTRUMENTED(klass)) {
172
		return klass->X.instrumented_class->GetName();
173
	} 
174
	else {
175
		if (klass->loaded == 0) {
176
			return(klass->class_name);
177
		}
178
		env = m_get_vm_pointer((void **)&env);
179
		class_name = (jstring)env->CallObjectMethod((jobject)klass->X.simplefied_class, m_j_l_class_getName);
180
		if (class_name == NULL)
181
			return (NULL);
182
		char *class_name_simple = (char *)env->GetStringUTFChars(class_name, NULL);
183
		char *ch = strchr(class_name_simple, '.');
184
		while (ch != NULL) {
185
			*ch = '/';
186
			ch = strchr(ch, '.');
187
		}
188
		return(class_name_simple);
189
	
190
	}
191
	return (NULL);
192
}
193
194
/** 
195
 * Function returns class loader.
196
 * @param klass - class handler
197
 * @return Class class loader handler.
198
 * @note Assertion is raised if klass is equal to null.
199
 */
200
extern "C" classloader_handler
201
class_get_class_loader( class_handler klass )
202
{
203
	if (IS_CLASS_INSTRUMENTED(klass)) {
204
		return (0);
205
	} else {
206
		assert(!"simplefied");
207
	}
208
	return (NULL);
209
}
210
211
/** 
212
 * Function returns super class of current class.
213
 * @param klass - class handler
214
 * @return Super class of current class.
215
 * @note Assertion is raised if klass is equal to null.
216
 */
217
extern "C" class_handler
218
class_get_super_class( class_handler klass )
219
{
220
221
	const char *class_name;
222
	const char *super_class_name = NULL;
223
	jobject this_class = NULL;
224
	jobject super_class;
225
	JNIEnv *env = NULL;
226
	env = m_get_vm_pointer((void **)&env);
227
	assert(env);
228
	int loaded = 1;
229
	if (klass->loaded == 0 && strcmp(klass->class_name,"java/lang/Object") == 0) return (NULL);
230
	if (klass->super_class != NULL) return (klass->super_class);
231
	
232
	if (IS_CLASS_INSTRUMENTED(klass)) {
233
		class_name = klass->X.instrumented_class->GetName();
234
		CConstPool* cpool = klass->X.instrumented_class->GetClass().GetConstPool();
235
		CCPUtf8Info* utfinfo = cpool->GetClass(klass->X.instrumented_class->GetClass().GetSuperClass());
236
		super_class_name = (const char *)utfinfo->GetBytes();
237
		assert(super_class_name);	
238
		super_class = (jclass)env->FindClass(super_class_name);		
239
	} 
240
	else {
241
		if (klass->loaded == 0) {
242
			assert(klass->class_name);
243
			this_class = (jclass)env->FindClass(klass->class_name);
244
			if (this_class == NULL && env->ExceptionCheck()) {
245
				env->ExceptionDescribe();
246
				env->ExceptionClear();
247
				//XXX: class wasn't found or loaded
248
				return (m_j_l_object_ch);
249
				//return (NULL);
250
			}
251
		}
252
		this_class = this_class?this_class:(jobject)klass->X.simplefied_class;
253
		super_class = (jobject)env->GetSuperclass((jclass)this_class);
254
	}
255
256
	if (super_class == NULL) {
257
		if (env->ExceptionCheck()) {
258
			env->ExceptionDescribe();
259
			env->ExceptionClear();
260
			//XXX: class wasn't found or loaded
261
			loaded = 0;
262
			//return (NULL);
263
		}
264
		else {
265
			klass->super_class = m_j_l_object_ch;
266
			return (m_j_l_object_ch);
267
			//return (NULL); /*it happends when klass is java.lang.Object*/
268
		}
269
	}
270
	else {
271
		jstring jclass_name = (jstring)env->CallObjectMethod(super_class, m_j_l_class_getName);
272
		if (jclass_name == NULL) {
273
			return (m_j_l_object_ch);
274
		}
275
		char *class_name_simple = (char *)env->GetStringUTFChars(jclass_name, NULL);
276
		assert (class_name_simple);
277
		char *ch = strchr(class_name_simple, '.');
278
		while (ch != NULL) {
279
			*ch = '/';
280
			ch = strchr(ch, '.');
281
		}
282
		super_class_name = class_name_simple;
283
	}
284
	
285
	//assert(super_class);
286
	class_handler ch;
287
	int status = create_class_handler(&ch, CLASS_HANDLER_SIMPLEFIED, super_class_name, loaded, super_class);
288
	assert(status == 0);
289
	return (ch);
290
}
291
292
/** 
293
 * Function checks if classes are equal.
294
 * @param klass1 - class handler
295
 * @param klass2 - class handler
296
 * @return If classes are equal returns <code>true</code>, else returns <code>false</code>.
297
 * @note Assertion is raised if klass1 or klass2 are equal to null.
298
 */
299
extern "C" unsigned
300
class_is_same_class( class_handler klass1, class_handler klass2 )
301
{
302
	assert(!"verifier entered!!");
303
	return 0;
304
}
305
306
static char* 
307
package_name(const char* kname)
308
{
309
	char *tokp;
310
	char *tok0;
311
	tokp = tok0 = (char *)&kname[0];
312
	tok0 = strchr(kname, '/');
313
	while (tok0 != NULL) {
314
		tokp = tok0;
315
		tok0 = strchr(tok0 + 1, '/');
316
	}
317
	return (tokp);
318
}
319
320
/** 
321
 * Function checks if classes have the same package.
322
 * @param klass1 - class handler
323
 * @param klass2 - class handler
324
 * @return If classes have the same package returns <code>true</code>, else returns <code>false</code>.
325
 * @note Assertion is raised if klass1 or klass2 are equal to null.
326
 */
327
extern "C" unsigned
328
class_is_same_package( class_handler klass1, class_handler klass2 ) 
329
{
330
	if (klass1 == klass2) {
331
		return (1);
332
	}
333
	else {
334
		const char *klass1_name = class_get_name(klass1);
335
		const char *klass2_name = class_get_name(klass2);
336
		char* package1 = package_name(klass1_name);
337
		char* package2 = package_name(klass2_name);
338
		int package1_len = (package1 - klass1_name);
339
		int package2_len = (package2 - klass2_name);
340
		if (package1_len != package2_len)
341
			return (0);
342
		return(strncmp(klass1_name, klass2_name, package2_len) == 0);
343
		assert(!"verifier entered!!");
344
	}
345
	return (0);
346
}
347
348
/**
349
 * Function checks if current class is interface.
350
 * @param klass - class handler
351
 * @return If class is interface returns <code>true</code>, else returns <code>false</code>.
352
 * @note Assertion is raised if klass is equal to null.
353
 */
354
// FIXME - There is a macro class_is_interface in Class.h
355
extern "C" unsigned
356
class_is_interface( class_handler klass ) 
357
{
358
	JNIEnv *env;
359
	env = m_get_vm_pointer((void **)&env);
360
	assert(env);
361
	if (IS_CLASS_INSTRUMENTED(klass)) {
362
		return (0);
363
	} 
364
	else {
365
		return (unsigned)(env->CallBooleanMethod((jobject)klass->X.simplefied_class, m_j_l_class_isInterface));
366
	}
367
	
368
	return (0);
369
}
370
371
/**
372
 * Function checks if current class is array.
373
 * @param klass - class handler
374
 * @return If class is array returns <code>true</code>, else returns <code>false</code>.
375
 * @note Assertion is raised if klass is equal to null.
376
 */
377
extern "C" unsigned
378
class_is_array( class_handler klass ) 
379
{
380
	assert(!"verifier entered!!");
381
	return (0);
382
}
383
384
/**
385
 * Function checks if current class is final.
386
 * @param klass - class handler
387
 * @return If class is final returns <code>true</code>, else returns <code>false</code>.
388
 * @note Assertion is raised if klass is equal to null.
389
 */
390
// FIXME - There is a macro class_is_final in Class.h
391
extern "C" unsigned
392
class_is_final_( class_handler klass ) 
393
{
394
	assert(!"verifier entered!!");
395
	return (0);
396
}
397
398
/**
399
 * Function receives number of super interfaces of class.
400
 * @param klass - class handler
401
 * @return Number of super interfaces of class.
402
 * @note Assertion is raised if klass is equal to null.
403
 */
404
extern "C" unsigned short
405
class_get_superinterface_number( class_handler klass )
406
{
407
	assert(!"verifier entered!!");
408
	return (0);
409
}
410
411
/**
412
 * Function receives super interface of class.
413
 * @param klass - class handler
414
 * @param index - super interface number
415
 * @return Super interface of class.
416
 * @note Assertion is raised if klass is equal to null or index is out of range.
417
 */
418
extern "C" class_handler
419
class_get_superinterface( class_handler klass, unsigned short index )
420
{
421
	assert(!"verifier entered!!");
422
	return (NULL);
423
}
424
425
/**
426
 * Function receives element class of array class.
427
 * @param klass - class handler
428
 * @return Element class of array class.
429
 * @note Assertion is raised if klass is equal to null or isn't array class.
430
 */
431
extern "C" class_handler
432
class_get_array_element_class( class_handler klass )
433
{
434
	assert(!"verifier entered!!");
435
	return (NULL);
436
}
437
438
439
/**
440
 * Function checks if class extends current class with given name.
441
 * @param klass      - checked klass
442
 * @param super_name - parent class name
443
 * @return If given class extends current class with given name,
444
 *         function returns its class handler, else function returns 0.
445
 * @note Assertion is raised if <i>klass</i> or <i>super_name</i> are equal to null.
446
 */
447
extern "C" class_handler
448
class_get_extended_class( class_handler klass, const char *super_name )
449
{
450
	return (NULL);
451
}
452
453
/**
454
 * Function returns number of methods for current class.
455
 * @param klass - class handler
456
 * @return Number of methods for class.
457
 * @note Assertion is raised if klass is equal to null.
458
 */
459
extern "C" unsigned short
460
class_get_method_number( class_handler klass )
461
{
462
	assert(!"verifier entered!!");
463
	return (0);
464
}
465
466
/** 
467
 * Function returns method of current class.
468
 * @param klass - class handler
469
 * @param index - method index
470
 * @return Method handler.
471
 * @note Assertion is raised if klass is equal to null or index is out of range.
472
 */
473
extern "C" method_handler
474
class_get_method( class_handler klass, unsigned short index )
475
{
476
	assert(!"verifier entered!!");
477
	return (NULL);
478
}
479
480
481
/**
482
 * Constant pool inteface
483
 */
484
485
/** 
486
 * Function returns class constant pool size.
487
 * @param klass - class handler
488
 * @return constant pool size
489
 * @note Assertion is raised if klass is equal to null.
490
 */
491
extern "C" unsigned short
492
class_cp_get_size( class_handler klass )
493
{
494
	if (IS_CLASS_INSTRUMENTED(klass)) {
495
		return klass->X.instrumented_class->GetClassBuilder().GetConstPool()->GetSize();
496
	} else {
497
		assert (!"not implemented yet!");
498
	}
499
	assert(!"verifier entered!!");
500
	return (0);
501
}
502
503
504
/** 
505
 * Function returns constant pool entry tag.
506
 * @param klass - class handler
507
 * @param index - constant pool entry index
508
 * @return constant pool entry tag
509
 * @note Assertion is raised if klass is equal to null or index is out of range.
510
 */
511
extern "C" unsigned char
512
class_cp_get_tag( class_handler klass, unsigned short index )
513
{
514
	if (IS_CLASS_INSTRUMENTED(klass)) {
515
		return (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]->GetTag();
516
	} else {
517
		assert (!"not implemented yet!");
518
	}
519
	return (0);
520
}
521
522
/** 
523
 * Function returns class name entry index in constant pool.
524
 * @param klass - class handler
525
 * @param index - constant pool entry index
526
 * @return class name entry index
527
 * @note Function is legal only for constant pool entry with CONSTANT_Class tags.
528
 * @note Assertion is raised if klass is equal to null or index is out of range.
529
 */
530
extern "C" unsigned short
531
class_cp_get_class_name_index( class_handler klass, unsigned short index )
532
{
533
	if (IS_CLASS_INSTRUMENTED(klass)) {
534
		CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index];
535
		assert(ccinfo->GetTag() == CONSTANT_Class);
536
		return ((CCPClassInfo *)ccinfo)->GetClassInd();
537
	} else {
538
		assert (!"not implemented yet!");
539
	}
540
	return (0);
541
}
542
543
/** 
544
 * Function returns class name entry index in constant pool.
545
 * @param klass - class handler
546
 * @param index - constant pool entry index
547
 * @return class name entry index
548
 * @note Function is legal for constant pool entry with 
549
 *       CONSTANT_Fieldref, CONSTANT_Methodref and CONSTANT_InterfaceMethodref tags.
550
 * @note Assertion is raised if klass is equal to null or index is out of range.
551
 */
552
extern "C" unsigned short
553
class_cp_get_ref_class_index( class_handler klass, unsigned short index )
554
{
555
	if (IS_CLASS_INSTRUMENTED(klass)) {
556
		CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index];
557
		unsigned char tag = ccinfo->GetTag();
558
		switch(tag) {
559
		case CONSTANT_Fieldref:
560
			return ((CCPFieldrefInfo *)ccinfo)->GetClassInd();
561
		break;
562
		case CONSTANT_Methodref:
563
			return ((CCPMethodrefInfo *)ccinfo)->GetClassInd();
564
		break;
565
		case CONSTANT_InterfaceMethodref:
566
			return ((CCPInterfaceMethodrefInfo *)ccinfo)->GetClassInd();
567
		break;
568
		default:
569
			assert(!"unsupported tag");
570
		}
571
	} else {
572
		assert (!"not implemented yet!");
573
	}
574
	return (0);
575
}
576
577
/** 
578
 * Function returns name_and_type entry index in constant pool.
579
 * @param klass - class handler
580
 * @param index - constant pool entry index
581
 * @return name_and_type entry index
582
 * @note Function is legal for constant pool entry with 
583
 *       CONSTANT_Fieldref, CONSTANT_Methodref and CONSTANT_InterfaceMethodref tags.
584
 * @note Assertion is raised if klass is equal to null or index is out of range.
585
 */
586
extern "C" unsigned short
587
class_cp_get_ref_name_and_type_index( class_handler klass, unsigned short index )
588
{
589
	if (IS_CLASS_INSTRUMENTED(klass)) {
590
		CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index];
591
		unsigned char tag = ccinfo->GetTag();
592
		switch(tag) {
593
		case CONSTANT_Fieldref:
594
			return ((CCPFieldrefInfo *)ccinfo)->GetNameAndTypeInd();
595
		break;
596
		case CONSTANT_Methodref:
597
			return ((CCPMethodrefInfo *)ccinfo)->GetNameAndTypeInd();
598
		break;
599
		case CONSTANT_InterfaceMethodref:
600
			return ((CCPInterfaceMethodrefInfo *)ccinfo)->GetNameAndTypeInd();
601
		break;
602
		default:
603
			assert(!"unsupported tag");
604
		}
605
	} else {
606
		assert (!"not implemented yet!");
607
	}
608
	return (0);
609
}
610
611
/** 
612
 * Function returns string entry index in constant pool.
613
 * @param klass - class handler
614
 * @param index - constant pool entry index
615
 * @return string entry index
616
 * @note Function is legal for constant pool entry with CONSTANT_String tags.
617
 * @note Assertion is raised if klass is equal to null or index is out of range.
618
 */
619
extern "C" unsigned short
620
class_cp_get_string_index( class_handler klass, unsigned short index )
621
{
622
	assert(!"verifier entered!!");
623
	return (0);
624
}
625
626
/** 
627
 * Function returns name entry index in constant pool.
628
 * @param klass - class handler
629
 * @param index - constant pool entry index
630
 * @return name entry index
631
 * @note Function is legal for constant pool entry with CONSTANT_NameAndType tags.
632
 * @note Assertion is raised if klass is equal to null or index is out of range.
633
 */
634
extern "C" unsigned short
635
class_cp_get_name_index( class_handler klass, unsigned short index )
636
{
637
	if (IS_CLASS_INSTRUMENTED(klass)) {
638
		CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index];
639
		unsigned char tag = ccinfo->GetTag();
640
		assert(tag == CONSTANT_NameAndType);
641
		return ((CCPNameAndTypeInfo *)ccinfo)->GetNameInd();
642
	} else {
643
		assert (!"not implemented yet!");
644
	}
645
	return (0);
646
}
647
648
/** 
649
 * Function returns descriptor entry index in constant pool.
650
 * @param klass - class handler
651
 * @param index - constant pool entry index
652
 * @return descriptor entry index
653
 * @note Function is legal for constant pool entry with CONSTANT_NameAndType tags.
654
 * @note Assertion is raised if klass is equal to null or index is out of range.
655
 */
656
extern "C" unsigned short
657
class_cp_get_descriptor_index( class_handler klass, unsigned short index )
658
{
659
	if (IS_CLASS_INSTRUMENTED(klass)) {
660
		CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index];
661
		unsigned char tag = ccinfo->GetTag();
662
		assert(tag == CONSTANT_NameAndType);
663
		return ((CCPNameAndTypeInfo *)ccinfo)->GetDescriptorInd();
664
	} else {
665
		assert (!"not implemented yet!");
666
	}
667
	return (0);
668
}
669
670
/** 
671
 * Function returns bytes for UTF8 constant pool entry.
672
 * @param klass - class handler
673
 * @param index - constant pool entry index
674
 * @return bytes for UTF8 constant pool entry
675
 * @note Function is legal for constant pool entry with CONSTANT_UTF8 tags.
676
 * @note Assertion is raised if klass is equal to null or index is out of range.
677
 */
678
extern "C" const char *
679
class_cp_get_utf8_bytes( class_handler klass, unsigned short index )
680
{
681
	if (IS_CLASS_INSTRUMENTED(klass)) {
682
		return (const char *)((CCPUtf8Info *)(*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index])->GetBytes();
683
	} else {
684
		assert (!"not implemented yet!");
685
	}
686
	return (0);
687
}
688
689
/**
690
 * Function sets verify data to a given class.
691
 * @param klass     - class handler
692
 * @param data      - verify data
693
 * @note Assertion is raised if class is equal to null.
694
 * @note Function makes non thread save operation and 
695
 *       must be called in thread safe point.
696
 */
697
extern "C" void
698
class_set_verify_data_ptr( class_handler klass, void *data )
699
{
700
	assert(!"verifier entered!!");
701
	return;
702
}
703
704
/**
705
 * Function returns verify data for a given class.
706
 * @param klass - class handler
707
 * @return Verify data for a given class.
708
 * @note Assertion is raised if klass is equal to null.
709
 */
710
extern "C" void *
711
class_get_verify_data_ptr( class_handler klass )
712
{
713
	assert(!"verifier entered!!");
714
	return (NULL);
715
}
716
717
/**
718
 * Function resolves class nonstatic method for constant pool entry.
719
 *
720
 * @param klass - class handle
721
 * @param index - constant pool entry index
722
 * @param exc   - pointer to exception
723
 *
724
 * @return Return nonstatic method resolved for constant pool entry.
725
 */
726
extern "C" method_handler
727
class_resolve_method( class_handler klass, unsigned short index )
728
{
729
	assert(!"verifier entered!!");
730
	return (NULL);
731
}
732
733
/**
734
 * Function resolves class nonstatic field for constant pool entry.
735
 *
736
 * @param klass - class handle
737
 * @param index - constant pool entry index
738
 * @param exc   - pointer to exception
739
 *
740
 * @return Return nonstatic field resolved for constant pool entry.
741
 */
742
extern "C" field_handler
743
class_resolve_nonstatic_field( class_handler klass, unsigned short index )
744
{
745
	assert(!"verifier entered!!");
746
	return (NULL);
747
}
748
749
/**
750
 * Method interface
751
 */
752
753
/**
754
 * Function returns a class in which the method is declared.
755
 * @param method - method handler
756
 * @return Return a class in which the method is declared.
757
 * @note Assertion is raised if <i>method</i> is equal to null.
758
 */
759
extern "C" class_handler
760
method_get_class( method_handler hmethod )
761
{
762
	if (hmethod == NULL) return (NULL);
763
	if (hmethod->magic == METHOD_HANDLER_SELF) {
764
		return (((CModuleJ *)hmethod->X.instrumented_method->GetModule())->GetClassHandler());
765
	}
766
	else {
767
		assert(!"verifier entered!!");
768
	}
769
	return (NULL);
770
}
771
772
/**
773
 * Function returns method name.
774
 * @param method - method handler
775
 * @return Method name bytes.
776
 * @note Assertion is raised if method is equal to null.
777
 */
778
extern "C" const char *
779
method_get_name( method_handler method )
780
{
781
	if (method->magic == METHOD_HANDLER_SELF) {
782
		return (method->X.instrumented_method->GetName());
783
	}
784
	else {
785
		assert(!"verifier entered!!");
786
	}
787
	return (NULL);
788
}
789
790
/**
791
 * Function returns method descriptor.
792
 * @param method - method handler
793
 * @return Method descriptor bytes.
794
 * @note Assertion is raised if method is equal to null.
795
 */
796
extern "C" const char *
797
method_get_descriptor( method_handler method )
798
{
799
	if (method->magic == METHOD_HANDLER_SELF) {
800
		return (method->X.instrumented_method->GetSignature());
801
	}
802
	else {
803
		assert(!"verifier entered!!");
804
	}
805
	return (NULL);
806
}
807
808
/**
809
 * Function returns method code length.
810
 * @param method - method handler
811
 * @return Method code length.
812
 * @note Assertion is raised if method is equal to null.
813
 */
814
extern "C" unsigned
815
method_get_bytecode_length( method_handler method )
816
{
817
	/*insert check about instrumentation*/
818
	if (method->magic == METHOD_HANDLER_SELF) {
819
		unsigned size = 0;
820
		CInstructions::const_iterator insIterator;
821
		if (method->X.instrumented_method->GetCodeAttribute() == NULL) return (0);
822
		return (method->X.instrumented_method->GetCodeAttribute()->GetCodeLength());
823
	}
824
	else {
825
		assert(!"verifier entered!!");
826
	}
827
	return (0);	
828
}
829
830
/**
831
 * Function returns method bytecode array.
832
 * @param method - method handler
833
 * @return Method bytecode array.
834
 * @note Assertion is raised if method is equal to null.
835
 */
836
extern "C" unsigned char *
837
method_get_bytecode( method_handler method )
838
{
839
	if (method->magic == METHOD_HANDLER_SELF) {
840
		return (method->X.instrumented_method->GetCodeAttribute()->GetCode());
841
	}
842
	else {
843
		assert(!"verifier entered!!");
844
	}
845
	return (NULL);	
846
}
847
848
/**
849
 * Function returns maximal local variables number of method.
850
 * @param method - method handler
851
 * @return Maximal local variables number of method.
852
 * @note Assertion is raised if method is equal to null.
853
 */
854
extern "C" unsigned
855
method_get_max_locals( method_handler method )
856
{
857
	if (method->magic == METHOD_HANDLER_SELF) {
858
		/*XXX: add check for instrumented method*/
859
		CMethodJ * jmethod = (CMethodJ *)(method->X.instrumented_method);
860
		return (jmethod->GetCodeAttribute()->GetMaxLocals());
861
	}
862
	else {
863
		assert(!"verifier entered!!");
864
	}
865
	return (0);	
866
	
867
}
868
869
/**
870
 * Function returns maximal stack deep of method.
871
 * @param method - method handler
872
 * @return Maximal stack deep of method.
873
 * @note Assertion is raised if method is equal to null.
874
 */
875
extern "C" unsigned 
876
method_get_max_stack( method_handler method )
877
{
878
	if (method->magic == METHOD_HANDLER_SELF) {
879
		CMethodJ * jmethod = (CMethodJ *)(method->X.instrumented_method);
880
		return (jmethod->GetCodeAttribute()->GetMaxStack());
881
	}
882
	else {
883
		assert(!"verifier entered!!");
884
	}
885
	return (0);	
886
}
887
888
/**
889
 * Function checks if method is static.
890
 * @param method - method handler
891
 * @return If method is static, function returns <code>true</code>,
892
 *         else returns <code>false</code>.
893
 * @note Assertion is raised if method is equal to null.
894
 */
895
extern "C" unsigned
896
method_is_static( method_handler method )
897
{
898
	if (method->magic == METHOD_HANDLER_SELF) {
899
		return (method->X.instrumented_method->GetAccessFlags() & ACC_STATIC);
900
	}
901
	else {
902
		//assert(!"verifier entered!!");
903
		return (0); /*we're assuming that this function called after class_resolve_method and couldn't return static methods*/
904
	}
905
	return (0);	
906
	
907
}
908
909
/**
910
 * Function checks if a given method is protected.
911
 *
912
 * @param method - method handle
913
 *
914
 * @return Return <code>TRUE</code> if a given method is protected.
915
 *
916
 * @note Assertion is raised if <i>method</i> is equal to null.
917
 */
918
extern "C" unsigned
919
method_is_protected( method_handler method )
920
{
921
	assert(!"verifier entered!!");
922
	return (0);
923
}
924
925
/**
926
 * Method exception handler
927
 */
928
929
/**
930
 * Function returns number of method exception handlers.
931
 * @param method - method handler
932
 * @return Number of method exception handlers.
933
 * @note Assertion is raised if method is equal to null.
934
 */
935
extern "C" unsigned short
936
method_get_exc_handler_number( method_handler method )
937
{
938
	return (method->X.instrumented_method->GetExTable()->size());
939
}
940
941
/**
942
 * Function obtains method exception handler info.
943
 * @param method     - method handler
944
 * @param index      - exception handler index number
945
 * @param start_pc   - resulting pointer to exception handler start program count
946
 * @param end_pc     - resulting pointer to exception handler end program count
947
 * @param handler_pc - resulting pointer to exception handler program count
948
 * @param catch_type - resulting pointer to constant pool entry index
949
 * @note Assertion is raised if method is equal to null or
950
 *       exception handler index is out of range or
951
 *       any pointer is equal to null.
952
 */
953
extern "C" void
954
method_get_exc_handler_info( method_handler method, unsigned short index,
955
                             unsigned short *start_pc, unsigned short *end_pc,
956
                             unsigned short *handler_pc, unsigned short *catch_type )
957
{
958
	class CExTable& exc = method->X.instrumented_method->GetCodeAttribute()->GetExTable();
959
	*start_pc = exc[index].GetStartPC();
960
	*end_pc = exc[index].GetEndPC();
961
	*handler_pc = exc[index].GetHandlerPC();
962
	*catch_type = exc[index].GetCatchtype();
963
964
	return;
965
}
966
967
/**
968
 * Gets number of exceptions a method can throw.
969
 * Parameter <i>hmethod</i> must not equal to <code>NULL</code>.
970
 *
971
 * @param hmethod   method handle
972
 *
973
 * @return          number of exceptions
974
 */
975
extern "C" unsigned short
976
method_get_number_exc_method_can_throw( method_handler hmethod )
977
{
978
	assert(!"verifier entered!!");
979
	return (0);
980
}
981
982
/**
983
 * Gets name of exception a method can throw.
984
 * Parameter <i>hmethod</i> must not equal to <code>NULL</code>.
985
 * If parameter <i>index</i> is out of range, returns <code>NULL</code>.
986
 *
987
 * @param hmethod   method handle
988
 * @param index     index of exception
989
 *
990
 * @return          name of exception
991
 */
992
extern "C" const char *
993
method_get_exc_method_can_throw( method_handler hmethod, unsigned short index )
994
{
995
	assert(!"verifier entered!!");
996
	return (NULL);
997
}
998
999
1000
/**
1001
 * Gets StackMapTable attribute.
1002
 * Parameter <i>hmethod</i> must not equal to <code>NULL</code>.
1003
 * If parameter <i>index</i> is out of range, returns <code>NULL</code>.
1004
 *
1005
 * @param hmethod   method handle
1006
 *
1007
 * @return          StackMapTable bytes
1008
 */
1009
extern "C" unsigned char *
1010
method_get_stackmaptable( method_handler hmethod )
1011
{
1012
	
1013
	CStackMapTableAttribute *attr = hmethod->X.instrumented_method->GetCodeAttribute()->GetStackMaps();
1014
	if (attr == NULL)
1015
		return (NULL);
1016
	u4 length = attr->GetLength();
1017
	u1 *stackmap = (u1 *)malloc(length);
1018
	CJMemStream mem_stream;
1019
	mem_stream.Open(stackmap, length);
1020
	CJStream stream(&mem_stream);
1021
	attr->Write(stream);
1022
	//return (attr->GetInfo());
1023
	return (stackmap);
1024
}
1025
1026
1027
//modifies start_pc, end_pc 
1028
extern "C" void 
1029
method_modify_exc_handler_info(method_handler method, 
1030
                                    unsigned short idx, 
1031
                                    unsigned short start_pc,
1032
                                    unsigned short end_pc, 
1033
                                    unsigned short handler_pc, 
1034
                                    unsigned short handler_cp_index )
1035
{
1036
1037
	assert(!"verifier entered!!");
1038
	return;
1039
}
1040
1041
// removes given exception handler (handlers with greater indexes shift)
1042
extern "C" void 
1043
method_remove_exc_handler( method_handler method, unsigned short idx )
1044
{
1045
	assert(!"verifier entered!!");
1046
	return;
1047
}
1048
1049
/**
1050
 * Class loader interface
1051
 */
1052
1053
/**
1054
 * Function sets verify data in class loader.
1055
 * @param classloader - class loader handler
1056
 * @param data        - verify data
1057
 * @note Assertion is raised if classloader is equal to null.
1058
 * @note Function makes non thread save operation and 
1059
 *       must be called in thread safe point.
1060
 */
1061
extern "C" void
1062
class_loader_set_verifier_data_ptr( classloader_handler classloader, void *data )
1063
{
1064
	assert(!"verifier entered!!");
1065
	return;
1066
}
1067
1068
/**
1069
 * Function returns verify data in class loader.
1070
 * @param classloader - class loader handler
1071
 * @return Verify data in class loader.
1072
 * @note Assertion is raised if classloader is equal to null.
1073
 */
1074
extern "C" void *
1075
class_loader_get_verifier_data_ptr( classloader_handler classloader )
1076
{
1077
	assert(!"verifier entered!!");
1078
	return (NULL);
1079
}
1080
1081
/**
1082
 * Function locks class loader.
1083
 * @param classloader - class loader handler
1084
 * @note Assertion is raised if classloader is equal to null.
1085
 */
1086
extern "C" void
1087
class_loader_lock( classloader_handler classloader )
1088
{
1089
	assert(!"verifier entered!!");
1090
	return;
1091
}
1092
1093
/**
1094
 * Function releases class loader.
1095
 * @param classloader - class loader handler
1096
 * @note Assertion is raised if classloader is equal to null.
1097
 */
1098
extern "C" void
1099
class_loader_unlock( classloader_handler classloader )
1100
{
1101
	assert(!"verifier entered!!");
1102
	return;
1103
}
1104
1105
/**
1106
 * Function returns loaded class in class loader.
1107
 * @param classloader - class loader handler
1108
 * @param name        - class name
1109
 * @return Loaded class in classloader or null if class isn't loaded in class loader.
1110
 * @note Assertion is raised if classloader or name are equal to null.
1111
 */
1112
extern "C" class_handler
1113
class_loader_lookup_class( classloader_handler classloader, const char *name )
1114
{
1115
	if (m_name2ch[name] != NULL && IS_CLASS_INSTRUMENTED(m_name2ch[name])) 
1116
		return (m_name2ch[name]);
1117
	else
1118
		return (NULL);
1119
}
1120
1121
/**
1122
 * Function returns loaded class in class loader.
1123
 * @param classloader - class loader handler
1124
 * @param name        - class name
1125
 * @return Loaded class in classloader if class isn't loaded in class loader 
1126
 *         function loads it.
1127
 * @note Assertion is raised if classloader or name are equal to null.
1128
 */
1129
extern "C" class_handler
1130
class_loader_load_class( classloader_handler classloader, const char *name )
1131
{
1132
	assert(!"verifier entered!!");
1133
	return (NULL);
1134
}
1135
1136
/**
1137
 * Function checks if the field is protected.
1138
 * @param field - field handler
1139
 * @return Returns <code>TRUE</code> if the field is protected.
1140
 */
1141
extern "C" unsigned
1142
field_is_protected( field_handler field )
1143
{
1144
	assert(!"verifier entered!!");
1145
	return (0);
1146
}
1147
1148
class_handler
1149
get_class_handler_from_builder(class CModuleJ *module) 
1150
{
1151
	class_handler ch;
1152
1153
	m_name2ch.clear();
1154
	int status = create_class_handler(&m_j_l_object_ch, CLASS_HANDLER_SIMPLEFIED, "java/lang/Object", 0, NULL);
1155
	assert(!status);
1156
	
1157
	status = create_class_handler(&ch, CLASS_HANDLER_INSTRUMENTED, module->GetName(), 1, module);
1158
	assert(!status);
1159
	return (ch);
1160
}
1161
1162
method_handler 
1163
get_method_handler_for_cmethod(class CMethod *method)
1164
{
1165
	class_handler ch = NULL;
1166
	method_handler mh = NULL;
1167
	int status;
1168
	status = create_class_handler(&ch, CLASS_HANDLER_INSTRUMENTED, (const char *)method->GetModule()->GetName(), 1, method->GetModule());
1169
	assert(!status);
1170
	status = create_method_handler(&mh, ch, METHOD_HANDLER_SELF, method);
1171
	assert(!status);
1172
	return (mh);
1173
}
1174
1175
extern "C" unsigned short
1176
class_cp_get_class_entry(class_handler klass, const char* name)
1177
{
1178
1179
	
1180
	CCPClassInfo *cinfo;
1181
	if (IS_CLASS_INSTRUMENTED(klass)) {
1182
		/*for this class we'll have entry somewhere in some future */
1183
		if (strcmp(klass->X.instrumented_class->GetName(), name) == 0) {
1184
			return (klass->X.instrumented_class->GetClass().GetThisClass());
1185
		}
1186
		assert(name);
1187
		cinfo = (klass->X.instrumented_class->GetClassBuilder().FindClass(name));
1188
		if (cinfo == NULL) {
1189
			/*should be created new class antry */
1190
			cinfo = *klass->X.instrumented_class->GetClassBuilder().CreateClassConstant(name);
1191
			assert(cinfo);
1192
		} 
1193
		return(cinfo->GetCpIndex());
1194
	} else {
1195
		assert (!"not implemented yet!");
1196
	}
1197
	return (0);
1198
}
1199
1200
int
1201
initialize_dynamic(get_vm_pointer_t a_get_vm_pointer)
1202
{
1203
	m_get_vm_pointer = (JNIEnv *(*)(void **))a_get_vm_pointer;
1204
	JNIEnv *env;
1205
	env = m_get_vm_pointer((void **)&env);
1206
	assert(env);
1207
	if (m_j_l_class) return (0);
1208
	
1209
	m_j_l_class = env->FindClass("java/lang/Class");
1210
	assert(m_j_l_class);
1211
	m_j_l_class_getName = env->GetMethodID(m_j_l_class, "getName", "()Ljava/lang/String;");
1212
	assert(m_j_l_class_getName);
1213
	m_j_l_class_getClassLoader = env->GetMethodID(m_j_l_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
1214
	assert(m_j_l_class_getClassLoader);
1215
	m_j_l_class_isInterface = env->GetMethodID(m_j_l_class, "isInterface", "()Z");
1216
	assert(m_j_l_class_isInterface);
1217
	
1218
	m_j_l_classloader = env->FindClass("java/lang/ClassLoader");
1219
	assert(m_j_l_classloader);
1220
	m_j_l_classloader_findLoadedClass = env->GetMethodID(m_j_l_classloader, "findLoadedClass", "(Ljava/lang/String;)Ljava/lang/Class;"); 
1221
	assert(m_j_l_classloader_findLoadedClass);
1222
1223
	return (0);
1224
}
1225
(-)src-native/BCI/BCIEng/BCIEngJ/class_interface_x.h (+46 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html         
7
 * $Id$ 
8
 * 
9
 * Contributors: 
10
 * Intel - Initial API and implementation 
11
 **********************************************************************/ 
12
13
#ifndef _CLASS_INTERFACE_X_H_
14
#define _CLASS_INTERFACE_X_H_
15
16
typedef unsigned long intptr;
17
18
19
#ifdef __cplusplus
20
//extern "C" {
21
#endif
22
23
#if 0
24
#include "class_interface.h"
25
#include "x_verifier.h"
26
#else
27
#define __INSURE__
28
#include "verifier-ext/class_interface.h"
29
#include "verifier-ext/x_verifier.h"
30
#endif
31
32
// removes given exception handler (handlers with greater indexes shift)
33
void method_remove_exc_handler( method_handler method, unsigned short idx );
34
35
//modifies start_pc, end_pc 
36
void method_modify_exc_handler_info(method_handler method, 
37
                                    unsigned short idx, 
38
                                    unsigned short start_pc,
39
                                    unsigned short end_pc, 
40
                                    unsigned short handler_pc, 
41
                                    unsigned short handler_cp_index );
42
unsigned short class_get_cp_class_entry(class_handler k_class, const char* name);
43
#ifdef __cplusplus
44
//}
45
#endif
46
#endif /*!_CLASS_INTERFACE_X_H_*/
(-)src-native/BCI/BCIEng/BCIEngProbe/BCIEngProbe.cpp (-5 / +21 lines)
Lines 20-25 Link Here
20
#pragma convert(819)	/* see comment in CommonDef.h about this */
20
#pragma convert(819)	/* see comment in CommonDef.h about this */
21
#endif
21
#endif
22
22
23
#include <assert.h>
24
23
#ifdef WIN32
25
#ifdef WIN32
24
#pragma warning(disable:4786)
26
#pragma warning(disable:4786)
25
#endif
27
#endif
Lines 32-37 Link Here
32
#include "BCIEngProbe.h"			// BCI Engine for Probe Kit
34
#include "BCIEngProbe.h"			// BCI Engine for Probe Kit
33
#include "BCIEngInterface.h"		// for callback message number defines
35
#include "BCIEngInterface.h"		// for callback message number defines
34
36
37
35
#include <stdio.h> // for sprintf on Linux
38
#include <stdio.h> // for sprintf on Linux
36
#ifdef MVS
39
#ifdef MVS
37
#    include <unistd.h> /* for __etoa */
40
#    include <unistd.h> /* for __etoa */
Lines 1830-1839 CBCIEngProbe::Instrument(void* i_pInClas Link Here
1830
	// Starting with the call to Open, we don't need to delete pClass any more:
1833
	// Starting with the call to Open, we don't need to delete pClass any more:
1831
	// The module owns it.
1834
	// The module owns it.
1832
	CModuleJ* pModuleJ = new CModuleJ;
1835
	CModuleJ* pModuleJ = new CModuleJ;
1836
	pModuleJ->UseStackMapCalculation(m_use_external_verifier);
1833
	pModuleJ->Open(pClass, true);
1837
	pModuleJ->Open(pClass, true);
1834
	pModuleJ->SetAccessFlags(pClass->GetAccessFlags());
1838
	pModuleJ->SetAccessFlags(pClass->GetAccessFlags());
1835
	pModuleJ->Parse();
1839
	if (pModuleJ->Parse() != 0) {
1836
1840
		*o_pcbOutClass = i_cbInClass;
1841
		*o_ppOutClass = i_pInClass;
1842
		delete pClass;
1843
		return false;
1844
	}
1845
	
1837
	// If we were asked to, then dump the module before and after instrumentation
1846
	// If we were asked to, then dump the module before and after instrumentation
1838
	const char *dump_output_file;
1847
	const char *dump_output_file;
1839
	if ((dump_output_file = getenv("PROBEKIT_DUMP_FILE")) != NULL) {
1848
	if ((dump_output_file = getenv("PROBEKIT_DUMP_FILE")) != NULL) {
Lines 1845-1850 CBCIEngProbe::Instrument(void* i_pInClas Link Here
1845
		output_stream << "=========== DUMP BEFORE INSTRUMENTATION" << endl;
1854
		output_stream << "=========== DUMP BEFORE INSTRUMENTATION" << endl;
1846
		pModuleJ->Dump(output_stream);
1855
		pModuleJ->Dump(output_stream);
1847
1856
1857
1848
#if defined(MVS) || defined(__OS400__)
1858
#if defined(MVS) || defined(__OS400__)
1849
		/* On EBCDIC systems, convert ASCII to EBCDIC */
1859
		/* On EBCDIC systems, convert ASCII to EBCDIC */
1850
		char* data = output_stream.str();
1860
		char* data = output_stream.str();
Lines 1864-1870 CBCIEngProbe::Instrument(void* i_pInClas Link Here
1864
	// to this module, but we still ran callsite probes against this
1874
	// to this module, but we still ran callsite probes against this
1865
	// module and maybe we didn't actually do anything.
1875
	// module and maybe we didn't actually do anything.
1866
	// In that case we should set out == in and return without calling emit.
1876
	// In that case we should set out == in and return without calling emit.
1867
1868
	pModuleJ->Emit();
1877
	pModuleJ->Emit();
1869
1878
1870
	// Tell the client that's driving us that we did something to this module
1879
	// Tell the client that's driving us that we did something to this module
Lines 1882-1887 CBCIEngProbe::Instrument(void* i_pInClas Link Here
1882
#else
1891
#else
1883
		ofstream output_stream(dump_output_file, ios::app);
1892
		ofstream output_stream(dump_output_file, ios::app);
1884
#endif
1893
#endif
1894
1885
		output_stream << "=========== DUMP AFTER INSTRUMENTATION" << endl;
1895
		output_stream << "=========== DUMP AFTER INSTRUMENTATION" << endl;
1886
		pModuleJ->Dump(output_stream);
1896
		pModuleJ->Dump(output_stream);
1887
1897
Lines 1898-1903 CBCIEngProbe::Instrument(void* i_pInClas Link Here
1898
	}
1908
	}
1899
1909
1900
	*o_pcbOutClass = pClass->GetSize();
1910
	*o_pcbOutClass = pClass->GetSize();
1911
	if (m_pfnMalloc == NULL) {
1912
		/*skipping*/
1913
		*o_pcbOutClass = i_cbInClass;
1914
		*o_ppOutClass = i_pInClass;
1915
		delete pClass;
1916
		return false;
1917
	}
1901
	*o_ppOutClass = m_pfnMalloc(*o_pcbOutClass);
1918
	*o_ppOutClass = m_pfnMalloc(*o_pcbOutClass);
1902
1919
1903
	CJMemStream		OutStream;					// Memory stream
1920
	CJMemStream		OutStream;					// Memory stream
Lines 1998-2004 CBCIEngProbe::Instrument(CModule* i_pmod Link Here
1998
	{
2015
	{
1999
		InstrumentMethod(*itrMeth); 
2016
		InstrumentMethod(*itrMeth); 
2000
	}
2017
	}
2001
2002
	// Process any staticInitializer fragments that matched this class,
2018
	// Process any staticInitializer fragments that matched this class,
2003
	// and default initializers for staticField elements in probes that matched.
2019
	// and default initializers for staticField elements in probes that matched.
2004
	HandleStaticInitializers(pmodj);
2020
	HandleStaticInitializers(pmodj);
Lines 3179-3185 CBCIEngProbe::InstrumentMethod(CMethod* Link Here
3179
	{
3195
	{
3180
		return;
3196
		return;
3181
	}
3197
	}
3182
3198
	
3183
	// Allow the client that's driving us to veto instrumentation of this module
3199
	// Allow the client that's driving us to veto instrumentation of this module
3184
	if (NULL != m_pfnCallback &&
3200
	if (NULL != m_pfnCallback &&
3185
		(m_wCBFlags & BCIENGINTERFACE_CALLBACK_METHOD) &&
3201
		(m_wCBFlags & BCIENGINTERFACE_CALLBACK_METHOD) &&
(-)src-native/BCI/BCIEng/BCIEngProbe/BCIEngProbe.dsp (-4 / +5 lines)
Lines 43-49 RSC=rc.exe Link Here
43
# PROP Ignore_Export_Lib 0
43
# PROP Ignore_Export_Lib 0
44
# PROP Target_Dir ""
44
# PROP Target_Dir ""
45
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BCIENGPROBE_EXPORTS" /YX /FD /c
45
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BCIENGPROBE_EXPORTS" /YX /FD /c
46
# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /I "..\..\BCIEng\\" /I "..\..\BCIEng\BCIEngJ" /I "..\..\JClass" /I "..\..\common" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
46
# ADD CPP /nologo /MT /W3 /GX /Zd /O2 /I "..\..\..\..\..\verifier\include" /I "..\..\..\..\..\verifier\open\include" /I "..\..\..\..\..\harmony-verifier\include" /I "..\..\..\..\..\harmony-verifier\open\include" /I "..\..\..\..\..\recomp" /I "..\..\..\..\..\harmony-verifier\verifier-3363\x_verifier" /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "..\..\BCIEng\\" /I "..\..\BCIEng\BCIEngJ" /I "..\..\JClass" /I "..\..\common" /I "..\..\..\..\..\org.apache.harmony_vmcore_verifier\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "VERIFIER_STANDALONE" /YX /FD /c
47
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
47
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
48
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
48
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
49
# ADD BASE RSC /l 0x409 /d "NDEBUG"
49
# ADD BASE RSC /l 0x409 /d "NDEBUG"
Lines 53-59 BSC32=bscmake.exe Link Here
53
# ADD BSC32 /nologo
53
# ADD BSC32 /nologo
54
LINK32=link.exe
54
LINK32=link.exe
55
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
55
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
56
# ADD LINK32 kernel32.lib bciengj.lib /nologo /dll /debug /machine:I386 /libpath:"..\..\..\bci\jclass\release" /libpath:"..\..\..\bci\bcieng\bciengj\release"
56
# ADD LINK32 bciengj.lib kernel32.lib verifier-ext.lib /nologo /dll /debug /machine:I386 /libpath:"..\..\..\bci\jclass\release" /libpath:"..\..\..\bci\bcieng\bciengj\release" /libpath:"..\..\..\..\..\org.apache.harmony_vmcore_verifier\lib\win\IA-32"
57
57
58
!ELSEIF  "$(CFG)" == "BCIEngProbe - Win32 Debug"
58
!ELSEIF  "$(CFG)" == "BCIEngProbe - Win32 Debug"
59
59
Lines 69-75 LINK32=link.exe Link Here
69
# PROP Ignore_Export_Lib 0
69
# PROP Ignore_Export_Lib 0
70
# PROP Target_Dir ""
70
# PROP Target_Dir ""
71
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BCIENGPROBE_EXPORTS" /YX /FD /GZ /c
71
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BCIENGPROBE_EXPORTS" /YX /FD /GZ /c
72
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\BCIEng\\" /I "..\..\BCIEng\BCIEngJ" /I "..\..\JClass" /I "..\..\common" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /FR /YX /FD /GZ /c
72
# ADD CPP /nologo /MDd /W3 /GX /Zd /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "..\..\BCIEng\\" /I "..\..\BCIEng\BCIEngJ" /I "..\..\JClass" /I "..\..\common" /I "..\..\..\..\..\org.apache.harmony_vmcore_verifier\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "VERIFIER_STANDALONE" /FR /YX /FD /GZ /c
73
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
73
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
74
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
74
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
75
# ADD BASE RSC /l 0x409 /d "_DEBUG"
75
# ADD BASE RSC /l 0x409 /d "_DEBUG"
Lines 79-85 BSC32=bscmake.exe Link Here
79
# ADD BSC32 /nologo
79
# ADD BSC32 /nologo
80
LINK32=link.exe
80
LINK32=link.exe
81
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
81
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
82
# ADD LINK32 bciengj.lib kernel32.lib /nologo /dll /incremental:no /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\bci\jclass\debug" /libpath:"..\..\..\bci\bcieng\bciengj\debug"
82
# ADD LINK32 verifier.lib jvm.lib bciengj.lib kernel32.lib verifier-ext.lib /nologo /dll /incremental:no /debug /machine:I386 /out:"Debug/BCIEngProbe.dll " /pdbtype:sept /libpath:"..\..\..\bci\jclass\debug" /libpath:"..\..\..\bci\bcieng\bciengj\debug" /libpath:"..\..\..\..\..\harmony-verifier\verifier\verifier_6\verifier\debug" /libpath:"C:\jrockit-jdk1.6.0_02\lib" /libpath:"..\..\..\..\..\org.apache.harmony_vmcore_verifier\lib\win\IA-32"
83
# SUBTRACT LINK32 /verbose
83
84
84
!ENDIF 
85
!ENDIF 
85
86
(-)src-native/BCI/BCIEng/BCIEngProbe/BCIEngProbe.h (+2 lines)
Lines 504-509 private: Link Here
504
	// These fields are reset and reused for each instrumented method
504
	// These fields are reset and reused for each instrumented method
505
	IP_t			m_ipFinally;				// Finally wrapper label
505
	IP_t			m_ipFinally;				// Finally wrapper label
506
	IP_t			m_ipCatchAll;				// catch-all wrapper label
506
	IP_t			m_ipCatchAll;				// catch-all wrapper label
507
friend class CBCIEngProbeInterface;
508
	bool m_use_external_verifier;
507
};
509
};
508
510
509
#endif // defined _BCIENGPROBE_H_
511
#endif // defined _BCIENGPROBE_H_
(-)src-native/BCI/BCIEng/BCIEngProbe/BCIEngProbeInterface.cpp (+31 lines)
Lines 20-25 Link Here
20
#pragma convert(819)	/* see comment in CommonDef.h about this */
20
#pragma convert(819)	/* see comment in CommonDef.h about this */
21
#endif
21
#endif
22
22
23
#include <assert.h>
24
23
#ifdef MVS 
25
#ifdef MVS 
24
#include <unistd.h> /* for __atoe */
26
#include <unistd.h> /* for __atoe */
25
#endif
27
#endif
Lines 37-42 Link Here
37
39
38
#define TOK_WHITESPACE " \t"
40
#define TOK_WHITESPACE " \t"
39
41
42
int g_use_verifier;
40
//------------------------------------------------------------------------------
43
//------------------------------------------------------------------------------
41
inline static unsigned ExceptionToError(CBCIEngProbeInterfaceException& ex)
44
inline static unsigned ExceptionToError(CBCIEngProbeInterfaceException& ex)
42
{
45
{
Lines 341-346 CBCIEngProbeInterface::Initialize(const Link Here
341
344
342
}
345
}
343
346
347
//------------------------------------------------------------------------------
348
void 
349
CBCIEngProbeInterface::UseStackMapRecalculation(bool a_use_recalculation)
350
{
351
	m_peng.m_use_external_verifier = a_use_recalculation;
352
}
344
353
345
//------------------------------------------------------------------------------
354
//------------------------------------------------------------------------------
346
void 
355
void 
Lines 439-444 unsigned Instrument(pbcieng_t i_pbcieng, Link Here
439
	try
448
	try
440
	{
449
	{
441
		CBCIEngProbeInterface* peng = (CBCIEngProbeInterface*)i_pbcieng;
450
		CBCIEngProbeInterface* peng = (CBCIEngProbeInterface*)i_pbcieng;
451
		peng->UseStackMapRecalculation(false);
452
		peng->Instrument(i_pInClass, i_cbInClass, o_ppOutClass, o_pcbOutClass);
453
	}
454
	catch (CBCIEngProbeInterfaceException& ex)
455
	{
456
		uErr = ExceptionToError(ex);
457
	}
458
	return uErr;
459
}
460
461
//------------------------------------------------------------------------------
462
unsigned Instrument2(pbcieng_t i_pbcieng, void* i_pInClass, size_t i_cbInClass, 
463
		            void** o_ppOutClass, size_t* o_pcbOutClass, void *(*pEnv)(void **))
464
{
465
	unsigned uErr = 0;
466
	initialize_dynamic(pEnv);
467
	try
468
	{
469
470
		CBCIEngProbeInterface* peng = (CBCIEngProbeInterface*)i_pbcieng;
471
		peng->UseStackMapRecalculation(true);
442
		peng->Instrument(i_pInClass, i_cbInClass, o_ppOutClass, o_pcbOutClass);
472
		peng->Instrument(i_pInClass, i_cbInClass, o_ppOutClass, o_pcbOutClass);
443
	}
473
	}
444
	catch (CBCIEngProbeInterfaceException& ex)
474
	catch (CBCIEngProbeInterfaceException& ex)
Lines 453-458 unsigned SetAllocator(pbcieng_t i_pbcien Link Here
453
{
483
{
454
	unsigned uErr = 0;
484
	unsigned uErr = 0;
455
	CBCIEngProbeInterface* peng = (CBCIEngProbeInterface*)i_pbcieng;
485
	CBCIEngProbeInterface* peng = (CBCIEngProbeInterface*)i_pbcieng;
486
	//assert(i_pfnMalloc);
456
	peng->SetAllocator(i_pfnMalloc);
487
	peng->SetAllocator(i_pfnMalloc);
457
	return uErr;
488
	return uErr;
458
}
489
}
(-)src-native/BCI/BCIEng/BCIEngProbe/BCIEngProbeInterface.h (+3 lines)
Lines 85-90 public: Link Here
85
85
86
private: 
86
private: 
87
	CBCIEngProbe m_peng;
87
	CBCIEngProbe m_peng;
88
	void UseStackMapRecalculation(bool a_use_recalculation);
89
	friend unsigned Instrument(pbcieng_t, void*, size_t , void** , size_t* );
90
	friend unsigned Instrument2(pbcieng_t, void*, size_t , void** , size_t*, void *(*f)(void **));
88
};
91
};
89
92
90
//------------------------------------------------------------------------------
93
//------------------------------------------------------------------------------
(-)src-native/BCI/BCIEng/BCIEngProbe/ProbeInstrumenter/ProbeInstrumenter.dsp (-2 / +2 lines)
Lines 42-48 RSC=rc.exe Link Here
42
# PROP Ignore_Export_Lib 0
42
# PROP Ignore_Export_Lib 0
43
# PROP Target_Dir ""
43
# PROP Target_Dir ""
44
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
44
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
45
# ADD CPP /nologo /W3 /GX /Zi /O2 /I "..\..\..\Common" /I "..\..\..\jclass" /I "..\..\..\bcieng" /I "..\..\..\bcieng\bciengj" /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR"..\Release\\" /YX /FD /c
45
# ADD CPP /nologo /W3 /GX /Zi /O2 /I "..\..\..\..\org.apache.harmony_vmcore_verifier\include" /I "..\..\..\Common" /I "..\..\..\jclass" /I "..\..\..\bcieng" /I "..\..\..\bcieng\bciengj" /I ".." /I "..\..\..\..\..\..\org.apache.harmony_vmcore_verifier\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR"..\Release\\" /YX /FD /c
46
# ADD BASE RSC /l 0x409 /d "NDEBUG"
46
# ADD BASE RSC /l 0x409 /d "NDEBUG"
47
# ADD RSC /l 0x409 /d "NDEBUG"
47
# ADD RSC /l 0x409 /d "NDEBUG"
48
BSC32=bscmake.exe
48
BSC32=bscmake.exe
Lines 66-72 LINK32=link.exe Link Here
66
# PROP Ignore_Export_Lib 0
66
# PROP Ignore_Export_Lib 0
67
# PROP Target_Dir ""
67
# PROP Target_Dir ""
68
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
68
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
69
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\Common" /I "..\..\..\jclass" /I "..\..\..\bcieng" /I "..\..\..\bcieng\bciengj" /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
69
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\..\..\..\org.apache.harmony_vmcore_verifier\include" /I "..\..\..\Common" /I "..\..\..\jclass" /I "..\..\..\bcieng" /I "..\..\..\bcieng\bciengj" /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
70
# ADD BASE RSC /l 0x409 /d "_DEBUG"
70
# ADD BASE RSC /l 0x409 /d "_DEBUG"
71
# ADD RSC /l 0x409 /d "_DEBUG"
71
# ADD RSC /l 0x409 /d "_DEBUG"
72
BSC32=bscmake.exe
72
BSC32=bscmake.exe
(-)src-native/BCI/Common/CommonDef.h (-9 / +14 lines)
Lines 22-35 Link Here
22
// For this header to work, you need to define one of these ARCH symbols:
22
// For this header to work, you need to define one of these ARCH symbols:
23
//
23
//
24
//	WIN32 (means x86)
24
//	WIN32 (means x86)
25
//	IA32_ARCH (means x86)
25
//  IPF_ARCH (means Itanium Processor Family)
26
//  IPF_ARCH (means Itanium Processor Family)
26
//  EM64T_ARCH (means Intel/AMD 64-bit processors)
27
//  EM64T_ARCH (means Intel/AMD 64-bit processors)
27
//	IA32_ARCH (means x86)
28
//	SPARC_ARCH
28
//	SPARC_ARCH
29
//	HPPA_ARCH
29
//	HPPA_ARCH
30
//	ALPHA_ARCH
30
//	ALPHA_ARCH
31
//	PPC_ARCH
31
//	PPC_ARCH
32
//  LINUX_PPC_ARCH  (LINUX PPC64)
33
//	OS390_ARCH (means zSeries)
32
//	OS390_ARCH (means zSeries)
34
//	AS400_ARCH (means iSeries)
33
//	AS400_ARCH (means iSeries)
35
//
34
//
Lines 72-81 Link Here
72
    // This brings _WINDOWS_ into scope. Use _WINDOWS_ to wrap Windows code.
71
    // This brings _WINDOWS_ into scope. Use _WINDOWS_ to wrap Windows code.
73
#   include <windows.h>           /* for lots o' stuff, but esp. _WINDOWS_ */
72
#   include <windows.h>           /* for lots o' stuff, but esp. _WINDOWS_ */
74
#   include <malloc.h>            /* for alloca */
73
#   include <malloc.h>            /* for alloca */
75
#elif defined(IPF_ARCH) || (EM64T_ARCH) || (LINUX_PPC_ARCH)
74
#elif defined(IPF_ARCH) || (EM64T_ARCH)
76
#   include <stdint.h>         /* for int64_t and uint64_t */
75
#   include <stdint.h>         /* for int64_t and uint64_t */
77
#endif
76
#endif
78
77
78
/* On LinuxPPC64 we need this to get int64_t */
79
#if defined(PPC_ARCH)
80
#   include </usr/include/sys/types.h>
81
#endif
79
/* Only on OS400, we need this to get malloc/free */
82
/* Only on OS400, we need this to get malloc/free */
80
#ifdef OS400
83
#ifdef OS400
81
#include <stdlib.h>
84
#include <stdlib.h>
Lines 113-127 typedef unsigned short WORD, *PWORD; Link Here
113
	typedef signed long long int int64_t;
116
	typedef signed long long int int64_t;
114
	typedef unsigned long long int uint64_t;
117
	typedef unsigned long long int uint64_t;
115
#else
118
#else
116
#if defined(_WINDOWS_)
119
#   if defined(_WINDOWS_)
117
		typedef __int64 int64_t;
120
		typedef __int64 int64_t;
118
		typedef unsigned __int64 uint64_t;
121
		typedef unsigned __int64 uint64_t;
119
#else
122
#elif defined(PPC_ARCH)
120
#       if !defined(IPF_ARCH) && !defined(EM64T_ARCH) && !defined(LINUX_PPC_ARCH) // Already being declared in stdint.h
121
		typedef long long int64_t;
122
		typedef unsigned long long uint64_t;
123
		typedef unsigned long long uint64_t;
124
#   else
125
#       if !defined(IPF_ARCH) && !defined(EM64T_ARCH)
126
	        typedef long long int64_t;
127
			typedef unsigned long long uint64_t;
123
#       endif
128
#       endif
124
#endif
129
#   endif
125
#endif
130
#endif
126
131
127
//------------------------------------------------------------------------------
132
//------------------------------------------------------------------------------
Lines 197-203 typedef unsigned short WORD, *PWORD; Link Here
197
///////
202
///////
198
#if defined(WIN32) || defined(IA32_ARCH) || defined(IPF_ARCH) || defined(EM64T_ARCH) || defined(ALPHA_ARCH)
203
#if defined(WIN32) || defined(IA32_ARCH) || defined(IPF_ARCH) || defined(EM64T_ARCH) || defined(ALPHA_ARCH)
199
#   define BIG_ENDIAN_HW
204
#   define BIG_ENDIAN_HW
200
#elif defined(SPARC_ARCH) || defined(HPPA_ARCH) || defined(PPC_ARCH) || defined(AS400_ARCH) || defined(OS390_ARCH) || defined(LINUX_PPC_ARCH)
205
#elif defined(SPARC_ARCH) || defined(HPPA_ARCH) || defined(PPC_ARCH) || defined(AS400_ARCH) || defined(OS390_ARCH)
201
#   define LITTLE_ENDIAN_HW
206
#   define LITTLE_ENDIAN_HW
202
#else
207
#else
203
#   error "Platform-specific configuration required"
208
#   error "Platform-specific configuration required"
(-)src-native/BCI/Common/JavaDef.h (-1 / +16 lines)
Lines 50-55 Link Here
50
#define CONSTANT_InterfaceMethodref	11		// Interface method refernce constant 
50
#define CONSTANT_InterfaceMethodref	11		// Interface method refernce constant 
51
#define CONSTANT_NameAndType		12		// Name and type constant
51
#define CONSTANT_NameAndType		12		// Name and type constant
52
52
53
#define CONSTANT_Unknown			0
53
// Array types
54
// Array types
54
#define T_BOOLEAN					4		// bool
55
#define T_BOOLEAN					4		// bool
55
#define T_CHAR						5		// char
56
#define T_CHAR						5		// char
Lines 60-66 Link Here
60
#define T_INT						10		// int
61
#define T_INT						10		// int
61
#define T_LONG						11		// long
62
#define T_LONG						11		// long
62
63
63
#define CONSTANT_Unknown			0
64
// stack map frame types (new in Java 6.0)
65
#define SAME_LOCALS_1_STACK_ITEM_EXTENDED   247
66
#define SAME_FRAME_EXTENDED                 251
67
#define FULL_FRAME                          255
68
69
// verification types (new in Java 6.0)
70
#define ITEM_Top                    0
71
#define ITEM_Integer                1
72
#define ITEM_Float                  2
73
#define ITEM_Double                 3
74
#define ITEM_Long                   4
75
#define ITEM_Null                   5
76
#define ITEM_UninitializedThis      6
77
#define ITEM_Object                 7
78
#define ITEM_Uninitialized          8
64
79
65
// ToDo: other Java specific definitions
80
// ToDo: other Java specific definitions
66
typedef unsigned char				u1;		// 1 byte
81
typedef unsigned char				u1;		// 1 byte
(-)src-native/BCI/JClass/JClassBuilder.cpp (-1 / +19 lines)
Lines 80-86 CJClassBuilder::GetThisClassName() Link Here
80
string
80
string
81
CJClassBuilder::GetSuperClassName()
81
CJClassBuilder::GetSuperClassName()
82
{
82
{
83
	CCPUtf8Info* pcpUtf8 = (CCPUtf8Info*)((*m_pConstPool)[GetSuperClass()]);
83
	CCPClassInfo* pccpClassInfo = (CCPClassInfo*)((*m_pConstPool)[GetSuperClass()]);
84
	CCPUtf8Info* pcpUtf8 = (CCPUtf8Info*)((*m_pConstPool)[pccpClassInfo->GetClassInd()]);
84
	string strSuperClass = (string)*pcpUtf8;
85
	string strSuperClass = (string)*pcpUtf8;
85
	return strSuperClass;
86
	return strSuperClass;
86
}
87
}
Lines 245-250 CJClassBuilder::FindClass(CSTR i_szName) Link Here
245
	CConstPool::iterator itr = m_pConstPool->begin();
246
	CConstPool::iterator itr = m_pConstPool->begin();
246
	while(itr != m_pConstPool->end())
247
	while(itr != m_pConstPool->end())
247
	{
248
	{
249
		if (*itr == NULL) return NULL;
248
		if((*itr)->GetTag() == CONSTANT_Class)
250
		if((*itr)->GetTag() == CONSTANT_Class)
249
		{
251
		{
250
			CCPClassInfo* pcpci = (CCPClassInfo*)*itr;
252
			CCPClassInfo* pcpci = (CCPClassInfo*)*itr;
Lines 278-283 CJClassBuilder::CreateStringConstant(CST Link Here
278
}
280
}
279
281
280
//------------------------------------------------------------------------------
282
//------------------------------------------------------------------------------
283
// CreateClassConstant
284
// In:
285
//	i_szClassName - class name
286
// Returns:
287
//	CCPClassInfo* - pointer to the class infoin the constant pool
288
//
289
CCPClassInfo* 
290
CJClassBuilder::CreateClassConstant(CSTR i_szClassName)
291
{
292
	u2 u2ClassName = m_pConstPool->Add(new CCPUtf8Info(i_szClassName));
293
	u2 u2ClassRef  = m_pConstPool->Add(new CCPClassInfo(u2ClassName));
294
	CCPClassInfo* pcpClass = (CCPClassInfo*)((*m_pConstPool)[u2ClassRef]);
295
	return pcpClass;
296
}
297
298
//------------------------------------------------------------------------------
281
// CreateIntegerConstant
299
// CreateIntegerConstant
282
// In:
300
// In:
283
//	i_int - Integer value to add
301
//	i_int - Integer value to add
(-)src-native/BCI/JClass/JClassBuilder.h (-1 / +2 lines)
Lines 62-68 public: Link Here
62
62
63
	// Constant pool manipulation
63
	// Constant pool manipulation
64
	CCPStringInfo* CreateStringConstant(CSTR i_szString);
64
	CCPStringInfo* CreateStringConstant(CSTR i_szString);
65
	CCPIntegerInfo* CreateIntegerConstant (JINTEGER i_int);
65
    CCPClassInfo* CreateClassConstant(CSTR i_szClassName);
66
    CCPIntegerInfo* CreateIntegerConstant (JINTEGER i_int);
66
	CCPLongInfo* CreateLongConstant(JLONG  i_long);
67
	CCPLongInfo* CreateLongConstant(JLONG  i_long);
67
	CCPFloatInfo* CreateFloatConstant(JFLOAT i_float);
68
	CCPFloatInfo* CreateFloatConstant(JFLOAT i_float);
68
	CCPDoubleInfo* CreateDoubleConstant(JDOUBLE i_double);
69
	CCPDoubleInfo* CreateDoubleConstant(JDOUBLE i_double);
(-)src-native/BCI/JClass/JClassFile.cpp (-9 / +806 lines)
Lines 47-54 Link Here
47
#  include <iostream>
47
#  include <iostream>
48
#endif
48
#endif
49
49
50
#include "JavaDef.h"
50
#include "CommonDef.h"
51
#include "CommonDef.h"
52
51
#include "JClassFile.h"
53
#include "JClassFile.h"
54
#include "JMemStream.h"
52
55
53
USE_NAMESPACE(std);
56
USE_NAMESPACE(std);
54
57
Lines 259-266 CCPUtf8Info::~CCPUtf8Info() Link Here
259
void
262
void
260
CCPUtf8Info::Read(CJStream& i_jstream)
263
CCPUtf8Info::Read(CJStream& i_jstream)
261
{
264
{
262
	i_jstream >> m_u2Length;
265
	i_jstream >> m_u2Length; 
263
	m_pu1Bytes = new u1[m_u2Length];
266
	m_pu1Bytes = new u1[m_u2Length + 1];
267
	m_pu1Bytes[m_u2Length] = 0; /*Helps standard string functions find end of the string*/
264
	i_jstream.ReadUtf8((void*)m_pu1Bytes, m_u2Length);
268
	i_jstream.ReadUtf8((void*)m_pu1Bytes, m_u2Length);
265
}
269
}
266
270
Lines 1738-1743 CJAttribs::Read(CJStream& i_jstream) Link Here
1738
		{
1742
		{
1739
			pCurrent = new CLocalVariableTypeTableAttribute(m_pClassFile);
1743
			pCurrent = new CLocalVariableTypeTableAttribute(m_pClassFile);
1740
		}
1744
		}
1745
 		else if(*pcpUtf8 == "StackMapTable")
1746
		{
1747
			pCurrent = new CStackMapTableAttribute(m_pClassFile);
1748
		}
1741
		else if(*pcpUtf8 == "Exceptions")
1749
		else if(*pcpUtf8 == "Exceptions")
1742
		{
1750
		{
1743
			pCurrent = new CExceptionsAttribute(m_pClassFile);
1751
			pCurrent = new CExceptionsAttribute(m_pClassFile);
Lines 2119-2124 CCodeAttribute::GetLocalVariableTypes() Link Here
2119
	return NULL;
2127
	return NULL;
2120
}
2128
}
2121
2129
2130
//------------------------------------------------------------------------------
2131
CStackMapTableAttribute* 
2132
CCodeAttribute::GetStackMaps()
2133
{
2134
	for(CJAttribs::iterator iter = m_Attribs.begin(); iter < m_Attribs.end(); iter++)
2135
	{
2136
		if(*(*iter)->GetName() == "StackMapTable")
2137
			return (CStackMapTableAttribute*)*iter;
2138
	}
2139
	return NULL;
2140
}
2141
2142
//------------------------------------------------------------------------------
2143
CStackMapTableAttribute* 
2144
CCodeAttribute::GetOrCreateStackMaps()
2145
{
2146
    // Return the StackMapTable attribute of this Code attribute, creating a new one
2147
    // if such an attribute does not exist
2148
2149
    CStackMapTableAttribute* result = NULL;
2150
	for(CJAttribs::iterator iter = m_Attribs.begin(); iter < m_Attribs.end(); iter++)
2151
	{
2152
		if(*(*iter)->GetName() == "StackMapTable")
2153
        {
2154
			result = (CStackMapTableAttribute*)*iter;
2155
        }
2156
	}
2157
2158
    if (result == NULL)
2159
    {
2160
        result = new CStackMapTableAttribute(m_pClassFile);
2161
        m_Attribs.push_back(result);
2162
    }
2163
    return result;
2164
}
2122
2165
2123
//==============================================================================
2166
//==============================================================================
2124
// CExceptionsAttribute implementation
2167
// CExceptionsAttribute implementation
Lines 2500-2505 CSourceDirAttribute::CSourceDirAttribute Link Here
2500
{}
2543
{}
2501
2544
2502
//==============================================================================
2545
//==============================================================================
2546
// CStackMapTableAttribute implementation
2547
//
2548
CVerificationTypeInfo::CVerificationTypeInfo(u1 i_u1Tag)
2549
: m_u1Tag(i_u1Tag)
2550
{
2551
}
2552
2553
CVerificationTypeInfo::~CVerificationTypeInfo()
2554
{
2555
}
2556
2557
void
2558
CVerificationTypeInfo::Read(CJStream& i_jstream)
2559
{
2560
    // m_u1Tag is read by the CVerificationTypes container.
2561
}
2562
2563
u2
2564
CVerificationTypeInfo::Read(u1 *i_tbl)
2565
{
2566
    // m_u1Tag is read by the CVerificationTypes container.
2567
	return 0;
2568
}
2569
2570
void
2571
CVerificationTypeInfo::Write(CJStream& i_jstream) const
2572
{
2573
    i_jstream << m_u1Tag;
2574
}
2575
2576
u4
2577
CVerificationTypeInfo::GetSize() const
2578
{
2579
    return sizeof(m_u1Tag);
2580
}
2581
2582
//------------------------------------------------------------------------------
2583
CVerificationTypes::~CVerificationTypes()
2584
{
2585
    for (iterator iter = begin(); iter != end(); iter++)
2586
    {
2587
        delete *iter;
2588
    }
2589
}
2590
2591
CVerificationTypes::CVerificationTypes(const CVerificationTypes &i_VerTypes)
2592
{
2593
    *this = i_VerTypes;
2594
}
2595
2596
CVerificationTypes&
2597
CVerificationTypes::operator =(const CVerificationTypes &i_VerTypes)
2598
{
2599
	for(iterator iter = begin(); iter != end(); iter++)
2600
	{
2601
		delete *iter;
2602
	}
2603
	if(!i_VerTypes.empty())
2604
	{
2605
		const_iterator iterIn;
2606
		clear();
2607
		for(iterIn = i_VerTypes.begin(); iterIn != i_VerTypes.end(); iterIn++)
2608
		{
2609
			push_back((*iterIn)->Clone());
2610
		}
2611
	}
2612
	return *this;
2613
}
2614
2615
void
2616
CVerificationTypes::Read(CJStream& i_jstream, u2 i_u2EntriesToRead)
2617
{
2618
    CVerificationTypeInfo* pCurrent;
2619
    
2620
    resize(i_u2EntriesToRead);
2621
    for(u2 u2Ind = 0; u2Ind < i_u2EntriesToRead; u2Ind++)
2622
    {
2623
        u1 u1Tag;
2624
        i_jstream >> u1Tag;
2625
        switch (u1Tag)
2626
        {
2627
        case ITEM_Top:
2628
        case ITEM_Integer:
2629
        case ITEM_Float:
2630
        case ITEM_Double:
2631
        case ITEM_Long:
2632
        case ITEM_Null:
2633
        case ITEM_UninitializedThis:
2634
            pCurrent = new CVerificationTypeInfo(u1Tag);
2635
            break;
2636
        case ITEM_Object:
2637
            pCurrent = new CVerificationTypeObjectInfo(u1Tag);
2638
            break;
2639
        case ITEM_Uninitialized:
2640
            pCurrent = new CVerificationTypeUninitializedVariableInfo(u1Tag);
2641
            break;
2642
        default:
2643
            throw CJClassFileException(CJClassFileException::X_INTERNAL_ERROR);
2644
        }
2645
2646
        pCurrent->Read(i_jstream);
2647
        (*this)[u2Ind] = pCurrent;
2648
    }
2649
}
2650
2651
void 
2652
CVerificationTypes::Write(CJStream& i_jstream) const
2653
{
2654
    for (u2 u2Ind = 0; u2Ind < size(); u2Ind++)
2655
    {
2656
        (*this)[u2Ind]->Write(i_jstream);
2657
    }
2658
}
2659
2660
u4
2661
CVerificationTypes::GetSize() const
2662
{
2663
    u4 u4Size = 0;
2664
	for (const_iterator iter = begin(); iter != end(); iter++)
2665
	{
2666
		u4Size += (*iter)->GetSize();
2667
	}
2668
    return u4Size;
2669
}
2670
2671
//------------------------------------------------------------------------------
2672
CVerificationTypeObjectInfo::CVerificationTypeObjectInfo(u1 i_u1Tag)
2673
: CVerificationTypeInfo(i_u1Tag)
2674
{
2675
}
2676
2677
CVerificationTypeObjectInfo::~CVerificationTypeObjectInfo()
2678
{
2679
}
2680
2681
void
2682
CVerificationTypeObjectInfo::Read(CJStream& i_jstream)
2683
{
2684
    CVerificationTypeInfo::Read(i_jstream);
2685
    i_jstream >> m_u2CpoolIndex;
2686
}
2687
2688
void
2689
CVerificationTypeObjectInfo::Write(CJStream& i_jstream) const
2690
{
2691
    CVerificationTypeInfo::Write(i_jstream);
2692
    i_jstream << m_u2CpoolIndex;
2693
}
2694
2695
u4
2696
CVerificationTypeObjectInfo::GetSize() const
2697
{
2698
    u4 u4Size = CVerificationTypeInfo::GetSize()
2699
        + sizeof(m_u2CpoolIndex);
2700
    return u4Size;
2701
}
2702
2703
//------------------------------------------------------------------------------
2704
CVerificationTypeUninitializedVariableInfo::CVerificationTypeUninitializedVariableInfo(u1 i_u1Tag)
2705
: CVerificationTypeInfo(i_u1Tag)
2706
{
2707
}
2708
2709
CVerificationTypeUninitializedVariableInfo::~CVerificationTypeUninitializedVariableInfo()
2710
{
2711
}
2712
2713
void
2714
CVerificationTypeUninitializedVariableInfo::Read(CJStream& i_jstream)
2715
{
2716
    CVerificationTypeInfo::Read(i_jstream);
2717
    i_jstream >> m_u2Offset;
2718
}
2719
2720
void
2721
CVerificationTypeUninitializedVariableInfo::Write(CJStream& i_jstream) const
2722
{
2723
    CVerificationTypeInfo::Write(i_jstream);
2724
    i_jstream << m_u2Offset;
2725
}
2726
2727
u4
2728
CVerificationTypeUninitializedVariableInfo::GetSize() const
2729
{
2730
    u4 u4Size = CVerificationTypeInfo::GetSize()
2731
        + sizeof(m_u2Offset);
2732
    return u4Size;
2733
}
2734
2735
//------------------------------------------------------------------------------
2736
CStackMapFrameInfo::CStackMapFrameInfo(u1 i_u1FrameType)
2737
: m_u1FrameType(i_u1FrameType)
2738
{
2739
    m_u2ByteCodeOffset = 0;
2740
    m_u2OffsetDelta = 0;
2741
}
2742
2743
CStackMapFrameInfo::~CStackMapFrameInfo()
2744
{
2745
}
2746
2747
void
2748
CStackMapFrameInfo::Read(CJStream& i_jstream)
2749
{
2750
    // m_u1FrameType is read by the CStackMapTable container
2751
}
2752
2753
void
2754
CStackMapFrameInfo::Write(CJStream& i_jstream) const
2755
{
2756
    i_jstream << m_u1FrameType;
2757
}
2758
2759
u4
2760
CStackMapFrameInfo::GetSize() const
2761
{
2762
    return sizeof(m_u1FrameType);
2763
}
2764
2765
void 
2766
CStackMapFrameInfo::SetByteCodeOffset(u2 i_u2Offset) 
2767
{ 
2768
    m_u2ByteCodeOffset = i_u2Offset; 
2769
}
2770
2771
void
2772
CStackMapFrameInfo::AdjustOffsetDelta(int i_s2PrevFrameOffset)
2773
{
2774
    int newOffsetDelta = m_u2ByteCodeOffset - 1 - i_s2PrevFrameOffset;
2775
    if (newOffsetDelta < 0)
2776
    {
2777
        // Frame order was changed. This is not supported
2778
        throw CJClassFileException(CJClassFileException::X_INTERNAL_ERROR);
2779
    }
2780
    m_u2OffsetDelta = (u2)newOffsetDelta; // this is a safe cast since newDelta >= 1
2781
}
2782
2783
CStackMapFrameInfo::CStackMapFrameInfo(const CStackMapFrameInfo &i_Other)
2784
: m_u2ByteCodeOffset(i_Other.m_u2ByteCodeOffset), m_u2OffsetDelta(i_Other.m_u2OffsetDelta),
2785
    m_u1FrameType(i_Other.m_u1FrameType)
2786
{
2787
}
2788
2789
//------------------------------------------------------------------------------
2790
CStackMapSameFrameInfo::CStackMapSameFrameInfo(u1 i_u1FrameType, bool i_IsExtended)
2791
: CStackMapFrameInfo(i_u1FrameType), m_IsExtended(i_IsExtended)
2792
{
2793
}
2794
2795
CStackMapSameFrameInfo::~CStackMapSameFrameInfo()
2796
{
2797
}
2798
2799
void
2800
CStackMapSameFrameInfo::Read(CJStream& i_jstream)
2801
{
2802
    CStackMapFrameInfo::Read(i_jstream);
2803
    if (m_IsExtended)
2804
    {
2805
        // SAME_FRAME_EXTENDED type
2806
        i_jstream >> m_u2OffsetDelta;
2807
    }
2808
    else        
2809
    {
2810
        // SAME frame type. offset_delta is stored in the tag
2811
        m_u2OffsetDelta = GetFrameType();
2812
    }
2813
}
2814
2815
void
2816
CStackMapSameFrameInfo::Write(CJStream& i_jstream) const
2817
{
2818
    CStackMapFrameInfo::Write(i_jstream);
2819
    if (m_IsExtended)
2820
    {
2821
        // SAME_FRAME_EXTENDED type
2822
        i_jstream << m_u2OffsetDelta;
2823
    }
2824
}
2825
2826
u4
2827
CStackMapSameFrameInfo::GetSize() const
2828
{
2829
    u4 u4Size = CStackMapFrameInfo::GetSize();
2830
    if (m_IsExtended)
2831
    {
2832
        u4Size += sizeof(m_u2OffsetDelta);
2833
    }
2834
    return u4Size;
2835
}
2836
2837
void
2838
CStackMapSameFrameInfo::AdjustOffsetDelta(int i_s2PrevFrameOffset)
2839
{
2840
    CStackMapFrameInfo::AdjustOffsetDelta(i_s2PrevFrameOffset);
2841
    if (m_u2OffsetDelta > 63)
2842
    {
2843
        // Frame type is SAME_FRAME_EXTENDED
2844
        m_u1FrameType = SAME_FRAME_EXTENDED;
2845
        m_IsExtended = true;
2846
    }
2847
    else
2848
    {
2849
        // Frame type is SAME_FRAME. offset_delta is stored in the tag
2850
        m_u1FrameType = (u1)m_u2OffsetDelta; // this is safe since m_u2OffsetDelta <= 63
2851
        m_IsExtended = false;
2852
    }
2853
}
2854
2855
CStackMapFrameInfo*
2856
CStackMapSameFrameInfo::Clone() const
2857
{
2858
    return new CStackMapSameFrameInfo(*this);
2859
}
2860
2861
//------------------------------------------------------------------------------
2862
CStackMapChopFrameInfo::CStackMapChopFrameInfo(u1 i_u1FrameType)
2863
: CStackMapFrameInfo(i_u1FrameType)
2864
{
2865
}
2866
2867
CStackMapChopFrameInfo::~CStackMapChopFrameInfo()
2868
{
2869
}
2870
2871
void
2872
CStackMapChopFrameInfo::Read(CJStream& i_jstream)
2873
{
2874
    CStackMapFrameInfo::Read(i_jstream);
2875
    i_jstream >> m_u2OffsetDelta;
2876
}
2877
2878
void
2879
CStackMapChopFrameInfo::Write(CJStream& i_jstream) const
2880
{
2881
    CStackMapFrameInfo::Write(i_jstream);
2882
    i_jstream << m_u2OffsetDelta;
2883
}
2884
2885
u4
2886
CStackMapChopFrameInfo::GetSize() const
2887
{
2888
    u4 u4Size = CStackMapFrameInfo::GetSize()
2889
        + sizeof(m_u2OffsetDelta);
2890
    return u4Size;
2891
}
2892
2893
CStackMapFrameInfo*
2894
CStackMapChopFrameInfo::Clone() const
2895
{
2896
    return new CStackMapChopFrameInfo(*this);
2897
}
2898
2899
//------------------------------------------------------------------------------
2900
CStackMapSameLocals1StackItemFrameInfo::CStackMapSameLocals1StackItemFrameInfo(u1 i_u1FrameType, 
2901
                                                                               bool i_IsExtended)
2902
: CStackMapFrameInfo(i_u1FrameType), m_IsExtended(i_IsExtended)
2903
{
2904
}
2905
2906
CStackMapSameLocals1StackItemFrameInfo::~CStackMapSameLocals1StackItemFrameInfo()
2907
{
2908
}
2909
2910
void
2911
CStackMapSameLocals1StackItemFrameInfo::Read(CJStream& i_jstream)
2912
{
2913
    CStackMapFrameInfo::Read(i_jstream);
2914
    if (m_IsExtended)
2915
    {
2916
        // SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED type
2917
        i_jstream >> m_u2OffsetDelta;
2918
    }
2919
    else        
2920
    {
2921
        // SAME_LOCALS_1_STACK_ITEM_FRAME frame type
2922
        m_u2OffsetDelta = GetFrameType() - 64;
2923
    }
2924
    m_Stack.Read(i_jstream, 1); // must hold exactly one stack item
2925
}
2926
2927
void
2928
CStackMapSameLocals1StackItemFrameInfo::Write(CJStream& i_jstream) const
2929
{
2930
    CStackMapFrameInfo::Write(i_jstream);
2931
    if (m_IsExtended)
2932
    {
2933
        // SAME_FRAME_EXTENDED type
2934
        i_jstream << m_u2OffsetDelta;
2935
    }
2936
    m_Stack.Write(i_jstream);
2937
}
2938
2939
u4
2940
CStackMapSameLocals1StackItemFrameInfo::GetSize() const
2941
{
2942
    u4 u4Size = CStackMapFrameInfo::GetSize();
2943
    if (m_IsExtended)
2944
    {
2945
        u4Size += sizeof(m_u2OffsetDelta);
2946
    }
2947
    u4Size += m_Stack.GetSize();
2948
    return u4Size;
2949
}
2950
2951
void
2952
CStackMapSameLocals1StackItemFrameInfo::AdjustOffsetDelta(int i_s2PrevFrameOffset)
2953
{
2954
    CStackMapFrameInfo::AdjustOffsetDelta(i_s2PrevFrameOffset);
2955
    if (m_u2OffsetDelta + 64 > 127)
2956
    {
2957
        // Frame type is SAME_LOCALS_1_STACK_FRAME_EXTENDED
2958
        m_u1FrameType = SAME_LOCALS_1_STACK_ITEM_EXTENDED;
2959
        m_IsExtended = true;
2960
    }
2961
    else
2962
    {
2963
        // Frame type is SAME_LOCALS_1_STACK_FRAME. offset_delta is stored in the tag
2964
        m_u1FrameType = (u1)(m_u2OffsetDelta + 64); // this is safe since m_u2OffsetDelta <= 63
2965
        m_IsExtended = false;
2966
    }
2967
}
2968
2969
CStackMapFrameInfo*
2970
CStackMapSameLocals1StackItemFrameInfo::Clone() const
2971
{
2972
    return new CStackMapSameLocals1StackItemFrameInfo(*this);
2973
}
2974
2975
CStackMapSameLocals1StackItemFrameInfo::CStackMapSameLocals1StackItemFrameInfo(const CStackMapSameLocals1StackItemFrameInfo &i_Other)
2976
: CStackMapFrameInfo(i_Other), m_Stack(i_Other.m_Stack), m_IsExtended(i_Other.m_IsExtended)
2977
{
2978
}
2979
2980
//------------------------------------------------------------------------------
2981
CStackMapAppendFrameInfo::CStackMapAppendFrameInfo(u1 i_u1FrameType)
2982
: CStackMapFrameInfo(i_u1FrameType)
2983
{
2984
}
2985
2986
CStackMapAppendFrameInfo::~CStackMapAppendFrameInfo()
2987
{
2988
}
2989
2990
void
2991
CStackMapAppendFrameInfo::Read(CJStream& i_jstream)
2992
{
2993
    CStackMapFrameInfo::Read(i_jstream);
2994
    i_jstream >> m_u2OffsetDelta;
2995
    m_Locals.Read(i_jstream, GetFrameType() - 251);
2996
}
2997
2998
void
2999
CStackMapAppendFrameInfo::Write(CJStream& i_jstream) const
3000
{
3001
    CStackMapFrameInfo::Write(i_jstream);
3002
    i_jstream << m_u2OffsetDelta;
3003
    m_Locals.Write(i_jstream);
3004
}
3005
3006
u4
3007
CStackMapAppendFrameInfo::GetSize() const
3008
{
3009
    u4 u4Size = CStackMapFrameInfo::GetSize()
3010
        + sizeof(m_u2OffsetDelta)
3011
        + m_Locals.GetSize();
3012
    return u4Size;
3013
}
3014
3015
CStackMapFrameInfo*
3016
CStackMapAppendFrameInfo::Clone() const
3017
{
3018
    return new CStackMapAppendFrameInfo(*this);
3019
}
3020
3021
CStackMapAppendFrameInfo::CStackMapAppendFrameInfo(const CStackMapAppendFrameInfo &i_Other)
3022
: CStackMapFrameInfo(i_Other), m_Locals(i_Other.m_Locals)
3023
{
3024
}
3025
3026
//------------------------------------------------------------------------------
3027
CStackMapFullFrameInfo::CStackMapFullFrameInfo(u1 i_u1FrameType)
3028
: CStackMapFrameInfo(i_u1FrameType), m_u2NumberOfLocals(0), m_u2NumberOfStackItems(0)
3029
{
3030
}
3031
3032
CStackMapFullFrameInfo::~CStackMapFullFrameInfo()
3033
{
3034
}
3035
3036
void
3037
CStackMapFullFrameInfo::Read(CJStream& i_jstream)
3038
{
3039
    CStackMapFrameInfo::Read(i_jstream);
3040
    i_jstream >> m_u2OffsetDelta
3041
              >> m_u2NumberOfLocals;
3042
    m_Locals.Read(i_jstream, m_u2NumberOfLocals);
3043
    i_jstream >> m_u2NumberOfStackItems;
3044
    m_Stack.Read(i_jstream, m_u2NumberOfStackItems);
3045
}
3046
3047
void
3048
CStackMapFullFrameInfo::Write(CJStream& i_jstream) const
3049
{
3050
    CStackMapFrameInfo::Write(i_jstream);
3051
    i_jstream << m_u2OffsetDelta
3052
              << m_u2NumberOfLocals;
3053
    m_Locals.Write(i_jstream);
3054
    i_jstream << m_u2NumberOfStackItems;
3055
    m_Stack.Write(i_jstream);
3056
}
3057
3058
u4
3059
CStackMapFullFrameInfo::GetSize() const
3060
{
3061
    u4 u4Size = CStackMapFrameInfo::GetSize()
3062
        + sizeof(m_u2OffsetDelta)
3063
        + sizeof(m_u2NumberOfLocals)
3064
        + m_Locals.GetSize()
3065
        + sizeof(m_u2NumberOfStackItems)
3066
        + m_Stack.GetSize();
3067
    return u4Size;
3068
}
3069
3070
CStackMapFrameInfo*
3071
CStackMapFullFrameInfo::Clone() const
3072
{
3073
    return new CStackMapFullFrameInfo(*this);
3074
}
3075
3076
CStackMapFullFrameInfo::CStackMapFullFrameInfo(const CStackMapFullFrameInfo &i_Other)
3077
: CStackMapFrameInfo(i_Other), m_Locals(i_Other.m_Locals), m_Stack(i_Other.m_Stack),
3078
    m_u2NumberOfLocals(i_Other.m_u2NumberOfLocals), 
3079
    m_u2NumberOfStackItems(i_Other.m_u2NumberOfStackItems)
3080
{
3081
}
3082
3083
//------------------------------------------------------------------------------
3084
CStackMapTable::~CStackMapTable()
3085
{
3086
    for (iterator iter = begin(); iter != end(); iter++)
3087
    {
3088
        delete *iter;
3089
    }
3090
}
3091
3092
void
3093
CStackMapTable::Read(CJStream& i_jstream)
3094
{
3095
    u2 u2Size;
3096
    CStackMapFrameInfo* pCurrent;
3097
    int s2PrevFrameOffset = -1;
3098
3099
    i_jstream >> u2Size;
3100
    resize(u2Size);
3101
    for(u2 u2Ind = 0; u2Ind < u2Size; u2Ind++)
3102
    {
3103
        u1 u1FrameType;
3104
        i_jstream >> u1FrameType;
3105
        if (u1FrameType >= 0 && u1FrameType <= 63)
3106
        {
3107
            pCurrent = new CStackMapSameFrameInfo(u1FrameType, false);
3108
        }
3109
        else if (u1FrameType >= 64 && u1FrameType <= 127)
3110
        {
3111
            pCurrent = new CStackMapSameLocals1StackItemFrameInfo(u1FrameType, false);
3112
        }
3113
        else if (u1FrameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED)
3114
        {
3115
            pCurrent = new CStackMapSameLocals1StackItemFrameInfo(u1FrameType, true);
3116
        }
3117
        else if (u1FrameType >= 248 && u1FrameType <= 250)
3118
        {
3119
            pCurrent = new CStackMapChopFrameInfo(u1FrameType);
3120
        }
3121
        else if (u1FrameType == SAME_FRAME_EXTENDED)
3122
        {
3123
            pCurrent = new CStackMapSameFrameInfo(u1FrameType, true);
3124
        }
3125
        else if (u1FrameType >= 252 && u1FrameType <= 254)
3126
        {
3127
            pCurrent = new CStackMapAppendFrameInfo(u1FrameType);
3128
        }
3129
        else if (u1FrameType == FULL_FRAME)
3130
        {
3131
            pCurrent = new CStackMapFullFrameInfo(u1FrameType);
3132
        }
3133
        else
3134
        {
3135
            // Unknown frame type
3136
            throw CJClassFileException(CJClassFileException::X_INTERNAL_ERROR);
3137
        }
3138
        
3139
        pCurrent->Read(i_jstream);
3140
        pCurrent->SetByteCodeOffset(s2PrevFrameOffset + 1 + pCurrent->m_u2OffsetDelta);
3141
        (*this)[u2Ind] = pCurrent;
3142
        s2PrevFrameOffset = pCurrent->GetByteCodeOffset();
3143
    }
3144
}
3145
3146
void
3147
CStackMapTable::AdjustOffsetDeltas()
3148
{
3149
    // Recalculate offset deltas for all frames. This function must be called before
3150
    // writing the Stack Map Table to the class file or calculating its size
3151
    CStackMapFrameInfo* pCurrent;
3152
    int s2PrevFrameOffset = -1;
3153
3154
    for (u2 u2Ind = 0; u2Ind < size(); u2Ind++)
3155
    {
3156
        pCurrent = (*this)[u2Ind];
3157
        pCurrent->AdjustOffsetDelta(s2PrevFrameOffset);
3158
        s2PrevFrameOffset = pCurrent->GetByteCodeOffset();
3159
    }
3160
}
3161
3162
CStackMapFrameInfo*
3163
CStackMapTable::GetFrameAtOffset(u2 i_u2Offset)
3164
{
3165
    bool found = false;
3166
    iterator it = begin();
3167
    for (; it != end(); ++it)
3168
    {
3169
        if ((*it)->GetByteCodeOffset() == i_u2Offset)
3170
        {
3171
            found = true;
3172
            break;
3173
        }
3174
    }
3175
3176
    if (found)
3177
    {
3178
        return (*it);
3179
    }
3180
    else
3181
    {
3182
        return NULL;
3183
    }
3184
}
3185
3186
void
3187
CStackMapTable::Write(CJStream& i_jstream) const
3188
{
3189
    i_jstream << (u2)size(); // the number_of_entries field
3190
3191
    CStackMapFrameInfo* pCurrent;
3192
    int s2PrevFrameOffset = -1;
3193
3194
    for (u2 u2Ind = 0; u2Ind < size(); u2Ind++)
3195
    {
3196
        pCurrent = (*this)[u2Ind];
3197
        pCurrent->Write(i_jstream);
3198
        s2PrevFrameOffset = pCurrent->GetByteCodeOffset();
3199
    }
3200
}
3201
3202
u4
3203
CStackMapTable::GetSize() const
3204
{
3205
    u4 u4Size = sizeof(u2); // the number_of_entries field
3206
    for (const_iterator iter = begin(); iter != end(); iter++)
3207
    {
3208
        u4Size += (*iter)->GetSize();
3209
    }
3210
    return u4Size;
3211
}
3212
3213
CStackMapTable& 
3214
CStackMapTable::operator = (const CStackMapTable& i_StackMaps)
3215
{
3216
	for(iterator iter = begin(); iter != end(); iter++)
3217
	{
3218
		delete *iter;
3219
	}
3220
	if(!i_StackMaps.empty())
3221
	{
3222
		const_iterator iterIn;
3223
		clear();
3224
		for(iterIn = i_StackMaps.begin(); iterIn != i_StackMaps.end(); iterIn++)
3225
		{
3226
			push_back((*iterIn)->Clone());
3227
		}
3228
	}
3229
	return *this;
3230
}
3231
3232
//------------------------------------------------------------------------------
3233
CStackMapTableAttribute::CStackMapTableAttribute(CJClassFile* i_pClassFile)
3234
: CAttributeInfo(i_pClassFile)
3235
{
3236
    u2 u2NameInd = i_pClassFile->GetConstPool()->Add(new CCPUtf8Info("StackMapTable"));
3237
    m_u2NameInd = u2NameInd;
3238
    m_StackMapTable.clear();
3239
}
3240
3241
CStackMapTableAttribute::~CStackMapTableAttribute()
3242
{
3243
}
3244
3245
void
3246
CStackMapTableAttribute::Read(CJStream& i_jstream)
3247
{
3248
	CAttributeInfo::Read(i_jstream);
3249
    m_StackMapTable.Read(i_jstream);
3250
}
3251
3252
void
3253
CStackMapTableAttribute::Write(CJStream& i_jstream) const
3254
{
3255
	const u4 u4Length = GetLength() - CAttributeInfo::SizeOf();
3256
	i_jstream	<<	m_u2NameInd
3257
				<<	u4Length;
3258
    m_StackMapTable.Write(i_jstream);
3259
}
3260
3261
u4
3262
CStackMapTableAttribute::GetSize() const
3263
{
3264
    return GetLength();
3265
}
3266
3267
u4
3268
CStackMapTableAttribute::GetLength() const
3269
{
3270
    u4 u4Length = CAttributeInfo::SizeOf()
3271
        + m_StackMapTable.GetSize();
3272
    return u4Length;
3273
}
3274
3275
void
3276
CStackMapTableAttribute::RereadFromBuffer(u1 *i_u1Tbl) 
3277
{
3278
	u2 u2skip = 0;
3279
	u4 u4attributeLenght = 0;
3280
	
3281
	if (i_u1Tbl == NULL) return;
3282
3283
	u2skip = i_u1Tbl[0];
3284
	u2skip <<= 8;
3285
	u2skip |= i_u1Tbl[1];
3286
3287
	u4attributeLenght = i_u1Tbl[2];
3288
	u4attributeLenght <<= 8;
3289
	u4attributeLenght |= i_u1Tbl[3];
3290
	u4attributeLenght <<= 8;
3291
	u4attributeLenght |= i_u1Tbl[4];
3292
	u4attributeLenght <<= 8;
3293
	u4attributeLenght |= i_u1Tbl[5];
3294
	m_u4Length = u4attributeLenght;
3295
	CJMemStream memstream;
3296
	memstream.Open(&i_u1Tbl[2], u4attributeLenght 
3297
		+ sizeof(u2) /*part of attribute header (its length)*/
3298
		+ 2 /*workaround for end buffer checking*/);
3299
	CJStream mem_jstream(&memstream);
3300
	//GetStackMapTable().RereadFromBuffer(&i_u1Tbl[6]);
3301
	this->Read(mem_jstream);
3302
}
3303
//==============================================================================
2503
// CJClassFile implementation
3304
// CJClassFile implementation
2504
//
3305
//
2505
3306
Lines 2544-2555 CJClassFile::Read(CJStream& i_jstream) Link Here
2544
	{
3345
	{
2545
		throw CJClassFileException(CJClassFileException::X_BAD_MAGIC);
3346
		throw CJClassFileException(CJClassFileException::X_BAD_MAGIC);
2546
	}
3347
	}
2547
	i_jstream	>>	m_u2MajorVersion;
2548
	if(CJClassFile::MajorVersion < m_u2MajorVersion)
2549
	{
2550
		throw CJClassFileException(CJClassFileException::X_BAD_VERSION);
2551
	}
2552
	i_jstream	>>	m_u2MinorVersion;
3348
	i_jstream	>>	m_u2MinorVersion;
3349
	i_jstream	>>	m_u2MajorVersion;
2553
	m_pConstPool->Read(i_jstream);
3350
	m_pConstPool->Read(i_jstream);
2554
	i_jstream	>>	m_u2AccessFlags
3351
	i_jstream	>>	m_u2AccessFlags
2555
				>>	m_u2ThisClass
3352
				>>	m_u2ThisClass
Lines 2565-2572 void Link Here
2565
CJClassFile::Write(CJStream& i_jstream) const
3362
CJClassFile::Write(CJStream& i_jstream) const
2566
{
3363
{
2567
	i_jstream	<<	m_u4Magic
3364
	i_jstream	<<	m_u4Magic
2568
				<<	m_u2MajorVersion
3365
				<<	m_u2MinorVersion
2569
				<<	m_u2MinorVersion;
3366
				<<	m_u2MajorVersion;
2570
	m_pConstPool->Write(i_jstream);
3367
	m_pConstPool->Write(i_jstream);
2571
	i_jstream	<<	m_u2AccessFlags
3368
	i_jstream	<<	m_u2AccessFlags
2572
				<<	m_u2ThisClass
3369
				<<	m_u2ThisClass
(-)src-native/BCI/JClass/JClassFile.h (-1 / +289 lines)
Lines 82-87 class CExceptionsAttribute; Link Here
82
class CLineNumberTableAttribute;
82
class CLineNumberTableAttribute;
83
class CLocalVariableTableAttribute;
83
class CLocalVariableTableAttribute;
84
class CLocalVariableTypeTableAttribute;
84
class CLocalVariableTypeTableAttribute;
85
class CStackMapTableAttribute;
85
86
86
//------------------------------------------------------------------------------
87
//------------------------------------------------------------------------------
87
// Container classes
88
// Container classes
Lines 672-677 public: Link Here
672
	CLineNumberTableAttribute* GetLineNumbers();
673
	CLineNumberTableAttribute* GetLineNumbers();
673
	CLocalVariableTableAttribute* GetLocalVariables();
674
	CLocalVariableTableAttribute* GetLocalVariables();
674
	CLocalVariableTypeTableAttribute* GetLocalVariableTypes();
675
	CLocalVariableTypeTableAttribute* GetLocalVariableTypes();
676
    CStackMapTableAttribute* GetStackMaps();
677
    CStackMapTableAttribute* GetOrCreateStackMaps();
678
675
679
676
protected:
680
protected:
677
	u2			m_u2MaxStack;
681
	u2			m_u2MaxStack;
Lines 899-904 private: Link Here
899
};
903
};
900
904
901
//------------------------------------------------------------------------------
905
//------------------------------------------------------------------------------
906
// Verification Type Information (new in Java 6)
907
//
908
// Represents the following verification types: Top, Integer, Float, Double, Long, Null,
909
// UninitializedThis
910
//
911
class CVerificationTypeInfo
912
{
913
public:
914
    CVerificationTypeInfo(u1 i_u1Tag);
915
    ~CVerificationTypeInfo();
916
    virtual void Read(CJStream& i_jstream);
917
	virtual u2 Read(u1* i_tbl);
918
	virtual void Write(CJStream& i_jstream) const;
919
	virtual u4	 GetSize() const;
920
    virtual CVerificationTypeInfo* Clone() const
921
    {
922
        return new CVerificationTypeInfo(*this);
923
    }
924
925
    u1 GetTag() { return m_u1Tag; }
926
927
private:
928
    u1 m_u1Tag;
929
};
930
931
//------------------------------------------------------------------------------
932
// Verification Type Information Vector
933
//
934
class CVerificationTypes : public vector<CVerificationTypeInfo*>
935
{
936
public:
937
    CVerificationTypes() { clear(); }
938
    CVerificationTypes(const CVerificationTypes &i_VerTypes);
939
	~CVerificationTypes();
940
941
    CVerificationTypes& operator = (const CVerificationTypes &i_VerTypes);
942
    
943
    virtual void	Read(CJStream& i_jstream, u2 i_u2EntriesToRead);
944
	virtual void	Write(CJStream& i_jstream) const;
945
	virtual u4	    GetSize() const;
946
947
private:
948
};
949
950
//------------------------------------------------------------------------------
951
// Verification Type Information: Object (new in Java 6)
952
//
953
class CVerificationTypeObjectInfo : public CVerificationTypeInfo
954
{
955
public:
956
    CVerificationTypeObjectInfo(u1 i_u1Tag);
957
    ~CVerificationTypeObjectInfo();
958
    virtual void Read(CJStream& i_jstream);
959
	virtual void Write(CJStream& i_jstream) const;
960
	virtual u4	 GetSize() const;
961
    virtual CVerificationTypeInfo* Clone() const
962
    {
963
        return new CVerificationTypeObjectInfo(*this);
964
    }
965
966
    u2   GetCpoolIndex() { return m_u2CpoolIndex; }
967
    void SetCpoolIndex(u2 i_u2CpoolIndex) { m_u2CpoolIndex = i_u2CpoolIndex; }
968
969
private:
970
    u2 m_u2CpoolIndex;
971
};
972
973
//------------------------------------------------------------------------------
974
// Verification Type Information: Uninitialized Variable (new in Java 6)
975
//
976
class CVerificationTypeUninitializedVariableInfo : public CVerificationTypeInfo
977
{
978
public:
979
    CVerificationTypeUninitializedVariableInfo(u1 i_u1Tag);
980
    ~CVerificationTypeUninitializedVariableInfo();
981
    virtual void Read(CJStream& i_jstream);
982
	virtual void Write(CJStream& i_jstream) const;
983
	virtual u4	 GetSize() const;
984
    virtual CVerificationTypeInfo* Clone() const
985
    {
986
        return new CVerificationTypeUninitializedVariableInfo(*this);
987
    }
988
989
    u2   GetOffset() { return m_u2Offset; }
990
    void SetOffset(u2 i_u2Offset) { m_u2Offset = i_u2Offset; }
991
992
private:
993
    u2 m_u2Offset;
994
};
995
996
997
//------------------------------------------------------------------------------
998
// Stack Map Frame Information (new in Java 6)
999
//
1000
class CStackMapFrameInfo
1001
{
1002
    friend class CStackMapTable;
1003
public:
1004
    CStackMapFrameInfo(u1 i_u1FrameType);
1005
    CStackMapFrameInfo(const CStackMapFrameInfo &i_Other);
1006
    ~CStackMapFrameInfo();
1007
1008
    virtual void Read(CJStream& i_jstream);
1009
	virtual void Write(CJStream& i_jstream) const;
1010
	virtual u4	 GetSize() const;
1011
    virtual CStackMapFrameInfo* Clone() const = 0;
1012
    
1013
    u1 GetFrameType() const { return m_u1FrameType; }
1014
    u2 GetByteCodeOffset() { return m_u2ByteCodeOffset; }
1015
    void SetByteCodeOffset(u2 i_u2Offset);
1016
1017
protected:
1018
    virtual void AdjustOffsetDelta(int i_s2PrevFrameOffset);
1019
    
1020
    u2 m_u2ByteCodeOffset;
1021
    u2 m_u2OffsetDelta;
1022
    u1 m_u1FrameType;
1023
};
1024
1025
//------------------------------------------------------------------------------
1026
// Stack Map Frame Information: same_frame and same_frame_extended (new in Java 6)
1027
//
1028
class CStackMapSameFrameInfo : public CStackMapFrameInfo
1029
{
1030
    friend class CStackMapTable;
1031
public:
1032
    CStackMapSameFrameInfo(u1 i_u1FrameType, bool i_IsExtended);
1033
    ~CStackMapSameFrameInfo();
1034
1035
    virtual void Read(CJStream& i_jstream);
1036
	virtual void Write(CJStream& i_jstream) const;
1037
	virtual u4	 GetSize() const;
1038
    virtual CStackMapFrameInfo* Clone() const;
1039
1040
protected:
1041
    virtual void AdjustOffsetDelta(int i_s2PrevFrameOffset);
1042
1043
private:
1044
    bool m_IsExtended;
1045
};
1046
1047
//------------------------------------------------------------------------------
1048
// Stack Map Frame Information: chop_frame (new in Java 6)
1049
//
1050
class CStackMapChopFrameInfo : public CStackMapFrameInfo
1051
{
1052
public:
1053
    CStackMapChopFrameInfo(u1 i_u1FrameType);
1054
    ~CStackMapChopFrameInfo();
1055
1056
    virtual void Read(CJStream& i_jstream);
1057
	virtual void Write(CJStream& i_jstream) const;
1058
	virtual u4	 GetSize() const;
1059
    virtual CStackMapFrameInfo* Clone() const;
1060
1061
private:
1062
};
1063
1064
//------------------------------------------------------------------------------
1065
// Stack Map Frame Information: same_locals_1_stack_item_frame and 
1066
//                              same_locals_1_stack_item_frame_extended (new in Java 6)
1067
//
1068
class CStackMapSameLocals1StackItemFrameInfo : public CStackMapFrameInfo
1069
{
1070
    friend class CStackMapTable;
1071
public:
1072
    CStackMapSameLocals1StackItemFrameInfo(u1 i_u1FrameType, bool i_IsExtended);
1073
    CStackMapSameLocals1StackItemFrameInfo(const CStackMapSameLocals1StackItemFrameInfo &i_Other);
1074
    ~CStackMapSameLocals1StackItemFrameInfo();
1075
1076
    virtual void Read(CJStream& i_jstream);
1077
	virtual void Write(CJStream& i_jstream) const;
1078
	virtual u4	 GetSize() const;
1079
    virtual CStackMapFrameInfo* Clone() const;
1080
1081
    CVerificationTypes& GetStack() { return m_Stack; }
1082
1083
protected:
1084
    virtual void AdjustOffsetDelta(int i_s2PrevFrameOffset);
1085
1086
private:
1087
    CStackMapSameLocals1StackItemFrameInfo& operator = (CStackMapSameLocals1StackItemFrameInfo &i_Other);
1088
1089
    CVerificationTypes m_Stack;     // A vector with 1 entry
1090
    bool m_IsExtended;
1091
};
1092
1093
//------------------------------------------------------------------------------
1094
// Stack Map Frame Information: append_frame (new in Java 6)
1095
//
1096
class CStackMapAppendFrameInfo : public CStackMapFrameInfo
1097
{
1098
public:
1099
    CStackMapAppendFrameInfo(u1 i_u1FrameType);
1100
    CStackMapAppendFrameInfo(const CStackMapAppendFrameInfo &i_Other);
1101
    ~CStackMapAppendFrameInfo();
1102
1103
    virtual void Read(CJStream& i_jstream);
1104
	virtual void Write(CJStream& i_jstream) const;
1105
	virtual u4	 GetSize() const;
1106
    virtual CStackMapFrameInfo* Clone() const;
1107
1108
    CVerificationTypes& GetLocals() { return m_Locals; }
1109
1110
private:
1111
    CStackMapAppendFrameInfo& operator = (const CStackMapAppendFrameInfo &i_Other);
1112
1113
    CVerificationTypes m_Locals;
1114
};
1115
1116
//------------------------------------------------------------------------------
1117
// Stack Map Frame Information: full_frame (new in Java 6)
1118
//
1119
class CStackMapFullFrameInfo : public CStackMapFrameInfo
1120
{
1121
public:
1122
    CStackMapFullFrameInfo(u1 i_u1FrameType);
1123
    CStackMapFullFrameInfo(const CStackMapFullFrameInfo &i_Other);
1124
    ~CStackMapFullFrameInfo();
1125
1126
    virtual void Read(CJStream& i_jstream);
1127
	virtual void Write(CJStream& i_jstream) const;
1128
	virtual u4	 GetSize() const;
1129
    virtual CStackMapFrameInfo* Clone() const;
1130
1131
    CVerificationTypes& GetLocals() { return m_Locals; }
1132
    CVerificationTypes& GetStack()  { return m_Stack;  }
1133
    
1134
private:
1135
    CStackMapFullFrameInfo& operator = (const CStackMapFullFrameInfo &i_Other);
1136
1137
    u2 m_u2NumberOfLocals;
1138
    CVerificationTypes m_Locals;
1139
    u2 m_u2NumberOfStackItems;
1140
    CVerificationTypes m_Stack;
1141
};
1142
1143
1144
//------------------------------------------------------------------------------
1145
// Stack Map Table (new in Java 6)
1146
//
1147
class CStackMapTable : public vector<CStackMapFrameInfo*>
1148
{
1149
public:
1150
    CStackMapTable() { clear(); }
1151
	~CStackMapTable();
1152
	virtual void	Read(CJStream& i_jstream);
1153
	virtual void	Write(CJStream& i_jstream) const;
1154
	virtual u4	    GetSize() const;
1155
1156
    void                AdjustOffsetDeltas();
1157
    CStackMapFrameInfo* GetFrameAtOffset(u2 i_u2Offset);
1158
	
1159
    CStackMapTable& operator = (const CStackMapTable& i_StackMaps);
1160
};
1161
1162
//------------------------------------------------------------------------------
1163
// Stack Map Table Attribute (new in Java 6 - [4.8.4])
1164
//
1165
class CStackMapTableAttribute : public CAttributeInfo
1166
{
1167
	friend class CStackMapTable;
1168
public:
1169
    CStackMapTableAttribute(CJClassFile* i_pClassFile);
1170
    ~CStackMapTableAttribute();
1171
	virtual void	Read(CJStream& i_jstream);
1172
	virtual void	Write(CJStream& i_jstream) const;
1173
	virtual u4	    GetSize() const;
1174
	virtual u4		GetLength() const;
1175
1176
    CStackMapTable& GetStackMapTable() { return m_StackMapTable; }
1177
	void SetStackMapTable(const CStackMapTable& i_stackmap) {m_StackMapTable = i_stackmap;}
1178
	void RereadFromBuffer(u1 *i_u1Tbl);
1179
1180
private:
1181
    CStackMapTable m_StackMapTable;
1182
1183
    // Disable assignment operator.
1184
    // To enable, implement these functions as public
1185
    CStackMapTableAttribute& operator = (const CStackMapTableAttribute& i_other) {}
1186
};
1187
1188
//------------------------------------------------------------------------------
902
// Interface information
1189
// Interface information
903
//
1190
//
904
class CInterfaceInfo
1191
class CInterfaceInfo
Lines 999-1004 public: Link Here
999
	virtual u4	 GetSize() const;
1286
	virtual u4	 GetSize() const;
1000
1287
1001
	u2			GetAccessFlags() {return m_u2AccessFlags;}
1288
	u2			GetAccessFlags() {return m_u2AccessFlags;}
1289
    void        SetAccessFlags(u2 i_u2AccessFlags) {m_u2AccessFlags = i_u2AccessFlags;}
1002
	u2			GetNameInd() const {return m_u2NameInd;}
1290
	u2			GetNameInd() const {return m_u2NameInd;}
1003
	u2			GetDescriptorInd() const {return m_u2DescriptorInd;}
1291
	u2			GetDescriptorInd() const {return m_u2DescriptorInd;}
1004
	CJAttribs&	GetAttribs()	{return m_Attribs;}
1292
	CJAttribs&	GetAttribs()	{return m_Attribs;}
Lines 1070-1076 public: Link Here
1070
class CJClassFile  
1358
class CJClassFile  
1071
{
1359
{
1072
public:
1360
public:
1073
	enum {MajorVersion = 3, MinorVersion = 46};	// TODO: comment on version 
1361
	enum {MajorVersion = 46, MinorVersion = 3};	// J2SE 1.2
1074
	CJClassFile();
1362
	CJClassFile();
1075
	virtual ~CJClassFile();
1363
	virtual ~CJClassFile();
1076
1364

Return to bug 148629