diff --git a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/MethodSizeExcessException.java b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/MethodSizeExcessException.java new file mode 100644 index 0000000..3935178 --- /dev/null +++ b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/MethodSizeExcessException.java @@ -0,0 +1,5 @@ +package org.ntlab.traceCollector.tracer; + +public class MethodSizeExcessException extends Exception { + +} diff --git a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/Tracer.java b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/Tracer.java index 268f7a5..b395b11 100644 --- a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/Tracer.java +++ b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/Tracer.java @@ -47,6 +47,8 @@ private static ClassPool cp = null; private static CodeConverter conv = null; private static IProgressMonitor monitor = null; + + private static final int MAX_METHOD_LENGTH = 65535; public static void main(String[] args) { initialize(new OutputStatementsGenerator(new JSONTraceGenerator())); // �����ŏo�̓t�H�[�}�b�g���w�肷�� @@ -138,33 +140,37 @@ * @param classPath �o�͂���N���X�t�@�C���̃N���X�p�X(null �̏ꍇ�͏o�͂��Ȃ�) */ public static void classInstrumentation(CtClass cc, String classPath) throws BadBytecode, NotFoundException, CannotCompileException, IOException { - classInitializerInstrumentation(cc, cc.getClassInitializer()); - - for (final CtConstructor c : cc.getDeclaredConstructors()) { - methodInstrumentation(cc, c); - } - for (final CtMethod m : cc.getDeclaredMethods()) { - methodInstrumentation(cc, m); - } try { - cc.instrument(conv); - } catch (CannotCompileException e) { - e.printStackTrace(); - } - if (classPath != null) { - if (classPath.endsWith("/")) { - classPath = classPath.substring(0, classPath.length() - 1); + classInitializerInstrumentation(cc, cc.getClassInitializer()); + + for (final CtConstructor c : cc.getDeclaredConstructors()) { + methodInstrumentation(cc, c); } - System.out.println(classPath + ":" + cc.getName()); -// cc.rebuildClassFile(); - cc.getClassFile().compact(); // ���ꂪ�Ȃ��ƁA���s���� java.lang.ClassFormatError: Truncated class file �ŗ����� - cc.debugWriteFile(classPath); -// cc.defrost(); - cc.detach(); - } + for (final CtMethod m : cc.getDeclaredMethods()) { + methodInstrumentation(cc, m); + } + try { + cc.instrument(conv); + } catch (CannotCompileException e) { + e.printStackTrace(); + } + if (classPath != null) { + if (classPath.endsWith("/")) { + classPath = classPath.substring(0, classPath.length() - 1); + } + System.out.println(classPath + ":" + cc.getName()); +// cc.rebuildClassFile(); + cc.getClassFile().compact(); // ���ꂪ�Ȃ��ƁA���s���� java.lang.ClassFormatError: Truncated class file �ŗ����� + cc.debugWriteFile(classPath); +// cc.defrost(); + cc.detach(); + } + } catch (MethodSizeExcessException e) { + e.printStackTrace(); + } } - private static void classInitializerInstrumentation(CtClass cc, CtConstructor classInitializer) throws BadBytecode, NotFoundException, CannotCompileException { + private static void classInitializerInstrumentation(CtClass cc, CtConstructor classInitializer) throws BadBytecode, NotFoundException, CannotCompileException, MethodSizeExcessException { if (classInitializer != null) { methodInstrumentation(cc, classInitializer); } else { @@ -176,7 +182,7 @@ } } - private static void methodInstrumentation(final CtClass cc, final CtBehavior m) throws BadBytecode, NotFoundException, CannotCompileException { + private static void methodInstrumentation(final CtClass cc, final CtBehavior m) throws BadBytecode, NotFoundException, CannotCompileException, MethodSizeExcessException { // ���\�b�h�{�̓��̊e�u���b�N�̍ŏ��ɏo�͕���}������(�o�͕��̑}���Ńu���b�N�������Ă��܂��̂ŁA��ɑ}�����Ă���) Block[] blocks = null; if (m instanceof CtMethod && !m.isEmpty()) { @@ -304,5 +310,8 @@ if (m.getMethodInfo().getCodeAttribute() != null) { m.getMethodInfo().getCodeAttribute().computeMaxStack(); // ���ꂪ�Ȃ��ƁA���s���� java.lang.VerifyError: Stack map does not match the one at exception handler... �ŗ����� } + if (!m.isEmpty() && m.getMethodInfo().getCodeAttribute().getCodeLength() > MAX_METHOD_LENGTH) { + throw new MethodSizeExcessException(); + } } }