From bbb0886c7f9ce4242067b2ae696cb3635ce33795 Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 00:04:47 +0900 Subject: [PATCH 1/8] Optimization part 3 --- src/Kernel/Mnemonics/_invokestatic.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Kernel/Mnemonics/_invokestatic.php b/src/Kernel/Mnemonics/_invokestatic.php index c6af99fd..0de99677 100644 --- a/src/Kernel/Mnemonics/_invokestatic.php +++ b/src/Kernel/Mnemonics/_invokestatic.php @@ -25,8 +25,6 @@ public function execute(): void $methodName = $cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getNameIndex()]->getString(); $signature = Formatter::parseSignature($cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getDescriptorIndex()]->getString()); - $this->getOptions('class_resolver') - ->resolve($cpInfo[$cpInfo[$cp->getClassIndex()]->getClassIndex()]->getString()); [$resourceType, $classObject] = $this->getOptions('class_resolver') ->resolve($cpInfo[$cpInfo[$cp->getClassIndex()]->getClassIndex()]->getString()); From bf4ebf5f53063d27c03e3f09b50d4111ed312f7a Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 14:26:51 +0900 Subject: [PATCH 2/8] Refactoring names --- src/Core/JVM/ActiveInterface.php | 29 ---------- ...ActiveAttributes.php => AttributePool.php} | 28 +++++++++- src/Core/JVM/ConstantPool.php | 7 ++- .../JVM/{ActiveFields.php => FieldPool.php} | 28 +++++++++- src/Core/JVM/InterfacePool.php | 55 +++++++++++++++++++ src/Core/JVM/Invoker/Invokable.php | 3 - .../JVM/{ActiveMethods.php => MethodPool.php} | 28 +++++++++- src/Core/JavaClass.php | 55 ++++++++++--------- src/Core/JavaClassInvoker.php | 4 +- 9 files changed, 172 insertions(+), 65 deletions(-) delete mode 100644 src/Core/JVM/ActiveInterface.php rename src/Core/JVM/{ActiveAttributes.php => AttributePool.php} (54%) rename src/Core/JVM/{ActiveFields.php => FieldPool.php} (54%) create mode 100644 src/Core/JVM/InterfacePool.php rename src/Core/JVM/{ActiveMethods.php => MethodPool.php} (53%) diff --git a/src/Core/JVM/ActiveInterface.php b/src/Core/JVM/ActiveInterface.php deleted file mode 100644 index 0bd51136..00000000 --- a/src/Core/JVM/ActiveInterface.php +++ /dev/null @@ -1,29 +0,0 @@ -reader = $reader; - for ($i = 0; $i < $entries; $i++) { - $this->entries[$i] = $reader->getBinaryReader()->readUnsignedShort(); - } - } - - public function getEntries() - { - return $this->entries; - } -} diff --git a/src/Core/JVM/ActiveAttributes.php b/src/Core/JVM/AttributePool.php similarity index 54% rename from src/Core/JVM/ActiveAttributes.php rename to src/Core/JVM/AttributePool.php index d13ecba8..2b705103 100644 --- a/src/Core/JVM/ActiveAttributes.php +++ b/src/Core/JVM/AttributePool.php @@ -2,10 +2,11 @@ namespace PHPJava\Core\JVM; use PHPJava\Core\Stream\Reader\ReaderInterface; +use PHPJava\Exceptions\ReadOnlyException; use PHPJava\Kernel\Attributes\AttributeInfo; use PHPJava\Utilities\DebugTool; -class ActiveAttributes +class AttributePool implements \ArrayAccess, \Countable { private $entries = []; private $reader; @@ -30,4 +31,29 @@ public function getEntries() { return $this->entries; } + + public function offsetExists($offset) + { + return isset($this->entries[$offset]); + } + + public function offsetGet($offset) + { + return $this->entries[$offset]; + } + + public function count() + { + return count($this->entries); + } + + public function offsetSet($offset, $value) + { + throw new ReadOnlyException('You cannot rewrite datum. The Attribute Pool is read-only.'); + } + + public function offsetUnset($offset) + { + throw new ReadOnlyException('You cannot rewrite datum. The Attribute Pool is read-only.'); + } } diff --git a/src/Core/JVM/ConstantPool.php b/src/Core/JVM/ConstantPool.php index fdf4d0a9..62fa6478 100644 --- a/src/Core/JVM/ConstantPool.php +++ b/src/Core/JVM/ConstantPool.php @@ -20,7 +20,7 @@ use PHPJava\Kernel\Structures\_Utf8; use PHPJava\Kernel\Structures\StructureInterface; -class ConstantPool implements \ArrayAccess +class ConstantPool implements \ArrayAccess, \Countable { private $entries = []; private $reader; @@ -102,6 +102,11 @@ public function offsetGet($offset) return $this->entries[$offset]; } + public function count() + { + return count($this->entries); + } + public function offsetSet($offset, $value) { throw new ReadOnlyException('You cannot rewrite datum. The Constant Pool is read-only.'); diff --git a/src/Core/JVM/ActiveFields.php b/src/Core/JVM/FieldPool.php similarity index 54% rename from src/Core/JVM/ActiveFields.php rename to src/Core/JVM/FieldPool.php index 0d1d0d34..7d09a121 100644 --- a/src/Core/JVM/ActiveFields.php +++ b/src/Core/JVM/FieldPool.php @@ -3,10 +3,11 @@ use PHPJava\Core\JavaClass; use PHPJava\Core\Stream\Reader\ReaderInterface; +use PHPJava\Exceptions\ReadOnlyException; use PHPJava\Kernel\Structures\_FieldInfo; use PHPJava\Utilities\DebugTool; -class ActiveFields +class FieldPool implements \ArrayAccess, \Countable { private $entries = []; private $reader; @@ -30,4 +31,29 @@ public function getEntries() { return $this->entries; } + + public function offsetExists($offset) + { + return isset($this->entries[$offset]); + } + + public function offsetGet($offset) + { + return $this->entries[$offset]; + } + + public function count() + { + return count($this->entries); + } + + public function offsetSet($offset, $value) + { + throw new ReadOnlyException('You cannot rewrite datum. The Field Pool is read-only.'); + } + + public function offsetUnset($offset) + { + throw new ReadOnlyException('You cannot rewrite datum. The Field Pool is read-only.'); + } } diff --git a/src/Core/JVM/InterfacePool.php b/src/Core/JVM/InterfacePool.php new file mode 100644 index 00000000..87757024 --- /dev/null +++ b/src/Core/JVM/InterfacePool.php @@ -0,0 +1,55 @@ +reader = $reader; + for ($i = 0; $i < $entries; $i++) { + $this->entries[$i] = $reader->getBinaryReader()->readUnsignedShort(); + } + } + + public function getEntries() + { + return $this->entries; + } + + public function offsetExists($offset) + { + return isset($this->entries[$offset]); + } + + public function offsetGet($offset) + { + return $this->entries[$offset]; + } + + public function count() + { + return count($this->entries); + } + + public function offsetSet($offset, $value) + { + throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.'); + } + + public function offsetUnset($offset) + { + throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.'); + } +} diff --git a/src/Core/JVM/Invoker/Invokable.php b/src/Core/JVM/Invoker/Invokable.php index f3b8177f..4c8d91cd 100644 --- a/src/Core/JVM/Invoker/Invokable.php +++ b/src/Core/JVM/Invoker/Invokable.php @@ -56,13 +56,10 @@ public function __construct(JavaClassInvoker $javaClassInvoker, array $methods, * @param mixed ...$arguments * @return null * @throws IllegalJavaClassException - * @throws NoSuchMethodException * @throws RuntimeException - * @throws UndefinedMethodException * @throws UndefinedOpCodeException * @throws \PHPJava\Exceptions\TypeException * @throws \PHPJava\Exceptions\UnableToFindAttributionException - * @throws \ReflectionException */ public function call(string $name, ...$arguments) { diff --git a/src/Core/JVM/ActiveMethods.php b/src/Core/JVM/MethodPool.php similarity index 53% rename from src/Core/JVM/ActiveMethods.php rename to src/Core/JVM/MethodPool.php index fdedebb7..790ae25d 100644 --- a/src/Core/JVM/ActiveMethods.php +++ b/src/Core/JVM/MethodPool.php @@ -2,10 +2,11 @@ namespace PHPJava\Core\JVM; use PHPJava\Core\Stream\Reader\ReaderInterface; +use PHPJava\Exceptions\ReadOnlyException; use PHPJava\Kernel\Structures\_MethodInfo; use PHPJava\Utilities\DebugTool; -class ActiveMethods +class MethodPool implements \ArrayAccess, \Countable { private $entries = []; private $reader; @@ -29,4 +30,29 @@ public function getEntries() { return $this->entries; } + + public function offsetExists($offset) + { + return isset($this->entries[$offset]); + } + + public function offsetGet($offset) + { + return $this->entries[$offset]; + } + + public function count() + { + return count($this->entries); + } + + public function offsetSet($offset, $value) + { + throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.'); + } + + public function offsetUnset($offset) + { + throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.'); + } } diff --git a/src/Core/JavaClass.php b/src/Core/JavaClass.php index 93d46272..5531c24c 100644 --- a/src/Core/JavaClass.php +++ b/src/Core/JavaClass.php @@ -1,10 +1,10 @@ activeInterfaces = new ActiveInterface( + $this->interfacePool = new InterfacePool( $reader, $reader->getBinaryReader()->readUnsignedShort(), $this->constantPool, $this->debugTool ); - $this->debugTool->getLogger()->info('Extracted interfaces: ' . count($this->activeInterfaces->getEntries())); + $this->debugTool->getLogger()->info('Extracted interfaces: ' . count($this->interfacePool)); // read fields - $this->activeFields = new ActiveFields( + $this->fieldPool = new FieldPool( $reader, $reader->getBinaryReader()->readUnsignedShort(), $this->constantPool, $this->debugTool ); - $this->debugTool->getLogger()->info('Extracted fields: ' . count($this->activeFields->getEntries())); + $this->debugTool->getLogger()->info('Extracted fields: ' . count($this->fieldPool)); // read methods - $this->activeMethods = new ActiveMethods( + $this->methodPool = new MethodPool( $reader, $reader->getBinaryReader()->readUnsignedShort(), $this->constantPool, $this->debugTool ); - $this->debugTool->getLogger()->info('Extracted methods: ' . count($this->activeMethods->getEntries())); + $this->debugTool->getLogger()->info('Extracted methods: ' . count($this->methodPool)); // read Attributes - $this->activeAttributes = new ActiveAttributes( + $this->attributePool = new AttributePool( $reader, $reader->getBinaryReader()->readUnsignedShort(), $this->constantPool, $this->debugTool ); - $this->debugTool->getLogger()->info('Extracted attributes: ' . count($this->activeAttributes->getEntries())); + $this->debugTool->getLogger()->info('Extracted attributes: ' . count($this->attributePool)); - foreach ($this->activeAttributes->getEntries() as $entry) { + foreach ($this->attributePool as $entry) { if ($entry->getAttributeData() instanceof InnerClassesAttribute) { $this->innerClasses = array_merge( $this->innerClasses, @@ -261,14 +262,14 @@ public function getInnerClasses(): array return $this->innerClasses; } - public function getFields(): array + public function getDefinedFields(): array { - return $this->activeFields->getEntries(); + return $this->fieldPool->getEntries(); } - public function getMethods(): array + public function getDefinedMethods(): array { - return $this->activeMethods->getEntries(); + return $this->methodPool->getEntries(); } public function getInvoker(): JavaClassInvoker diff --git a/src/Core/JavaClassInvoker.php b/src/Core/JavaClassInvoker.php index 73cacecd..8db62805 100644 --- a/src/Core/JavaClassInvoker.php +++ b/src/Core/JavaClassInvoker.php @@ -55,7 +55,7 @@ public function __construct(JavaClass $javaClass, array $options) $this->options = $options; $cpInfo = $javaClass->getConstantPool(); - foreach ($javaClass->getMethods() as $methodInfo) { + foreach ($javaClass->getDefinedMethods() as $methodInfo) { /** * @var _MethodInfo $methodInfo */ @@ -68,7 +68,7 @@ public function __construct(JavaClass $javaClass, array $options) } } - foreach ($javaClass->getFields() as $fieldInfo) { + foreach ($javaClass->getDefinedFields() as $fieldInfo) { /** * @var _FieldInfo $fieldInfo */ From 0569bd8a88dbaea86e10b17d6e04acd155c1a3df Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 14:34:24 +0900 Subject: [PATCH 3/8] Fix --- src/Core/JavaClass.php | 2 -- src/Kernel/Mnemonics/_getstatic.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Core/JavaClass.php b/src/Core/JavaClass.php index 5531c24c..cc8f6ab0 100644 --- a/src/Core/JavaClass.php +++ b/src/Core/JavaClass.php @@ -84,8 +84,6 @@ class JavaClass implements JavaClassInterface private $startTime = 0.0; /** - * JavaClass constructor. - * * @param ReaderInterface $reader * @param array $options * @throws ValidatorException diff --git a/src/Kernel/Mnemonics/_getstatic.php b/src/Kernel/Mnemonics/_getstatic.php index 7ee9bee7..56b21a69 100644 --- a/src/Kernel/Mnemonics/_getstatic.php +++ b/src/Kernel/Mnemonics/_getstatic.php @@ -21,7 +21,7 @@ public function execute(): void $signature = Formatter::parseSignature($cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getDescriptorIndex()]->getString()); if ($cp instanceof _Fieldref) { - foreach ($this->javaClass->getFields() as $field) { + foreach ($this->javaClass->getDefinedFields() as $field) { if ($cpInfo[$field->getNameIndex()]->getString() === $cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getNameIndex()]->getString()) { // push stack $fieldName = $cpInfo[$field->getNameIndex()]->getString(); From ea80d374df43d3d9db94977868205a4cd22216fc Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 15:26:54 +0900 Subject: [PATCH 4/8] Optimized binary reader --- src/Core/JVM/AttributePool.php | 10 ++++++---- src/Core/JVM/Stream/BinaryReader.php | 14 +++++--------- src/Core/JavaClass.php | 2 ++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Core/JVM/AttributePool.php b/src/Core/JVM/AttributePool.php index 2b705103..475aee11 100644 --- a/src/Core/JVM/AttributePool.php +++ b/src/Core/JVM/AttributePool.php @@ -20,10 +20,12 @@ public function __construct( $this->reader = $reader; for ($i = 0; $i < $entries; $i++) { // not implemented, read only - $this->entries[$i] = new AttributeInfo($reader); - $this->entries[$i]->setConstantPool($constantPool); - $this->entries[$i]->setDebugTool($debugTool); - $this->entries[$i]->execute(); + $entry = (new AttributeInfo($reader)) + ->setConstantPool($constantPool) + ->setDebugTool($debugTool); + $entry->execute(); + + $this->entries[] = $entry; } } diff --git a/src/Core/JVM/Stream/BinaryReader.php b/src/Core/JVM/Stream/BinaryReader.php index 4f668e4e..ed909c22 100644 --- a/src/Core/JVM/Stream/BinaryReader.php +++ b/src/Core/JVM/Stream/BinaryReader.php @@ -35,17 +35,17 @@ public function readByte() public function readUnsignedByte() { - return (int) sprintf('%u', ord($this->read(1))); + return current(unpack('C', $this->read(1))); } public function readUnsignedInt() { - return base_convert(bin2hex($this->read(4)), 16, 10); + return current(unpack('N', $this->read(4))); } public function readUnsignedShort() { - return (int) sprintf('%u', hexdec(bin2hex($this->read(2)))); + return current(unpack('n', $this->read(2))); } public function readInt() @@ -57,16 +57,12 @@ public function readInt() public function readShort() { $short = $this->readUnsignedShort(); - return (($short & 0x8000) > 0) ? ($short - 0xFFFF - 1) : $short ; + return (($short & 0x8000) > 0) ? ($short - 0xFFFF - 1) : $short; } public function readUnsignedLong() { - if (PHP_INT_MAX === 2147483647) { - return base_convert(bin2hex($this->read(8)), 16, 10); - } - - return (int) sprintf('%u', hexdec(bin2hex($this->read(8)))); + return current(unpack('J', $this->read(8))); } public function readLong() diff --git a/src/Core/JavaClass.php b/src/Core/JavaClass.php index cc8f6ab0..c97b30e0 100644 --- a/src/Core/JavaClass.php +++ b/src/Core/JavaClass.php @@ -224,6 +224,8 @@ public function __construct(ReaderInterface $reader, array $options = []) $options ); + var_dump(microtime(true) - $this->startTime); + if ($this->invoker->getStatic()->getMethods()->has('')) { $this->invoker ->getStatic() From 931c7acbd5b2b881d0e75c40f9938d16cd5b2163 Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 15:33:17 +0900 Subject: [PATCH 5/8] Remove unneeded var_dump --- src/Core/JavaClass.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Core/JavaClass.php b/src/Core/JavaClass.php index c97b30e0..cc8f6ab0 100644 --- a/src/Core/JavaClass.php +++ b/src/Core/JavaClass.php @@ -224,8 +224,6 @@ public function __construct(ReaderInterface $reader, array $options = []) $options ); - var_dump(microtime(true) - $this->startTime); - if ($this->invoker->getStatic()->getMethods()->has('')) { $this->invoker ->getStatic() From fb88d1bcea26a1b0411e2204be25695ea74e6fec Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 15:42:15 +0900 Subject: [PATCH 6/8] Fix mistaken attribution reading --- src/Kernel/Attributes/CodeAttribute.php | 6 +--- .../Attributes/LineNumberTableAttribute.php | 4 +-- src/Kernel/Structures/_ExceptionTable.php | 28 +++---------------- src/Kernel/Structures/_LineNumberTable.php | 2 ++ 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/Kernel/Attributes/CodeAttribute.php b/src/Kernel/Attributes/CodeAttribute.php index 98b618bb..6436fa3b 100644 --- a/src/Kernel/Attributes/CodeAttribute.php +++ b/src/Kernel/Attributes/CodeAttribute.php @@ -40,11 +40,7 @@ public function execute(): void $exceptionTable = new \PHPJava\Kernel\Structures\_ExceptionTable($this->reader); $exceptionTable->setConstantPool($this->getConstantPool()); $exceptionTable->setDebugTool($this->getDebugTool()); - $exceptionTable->setStartPc($this->readUnsignedShort()) - ->setEndPc($this->readUnsignedShort()) - ->setHandlerPc($this->readUnsignedShort()) - ->setCatchType($this->readUnsignedShort()) - ->execute(); + $exceptionTable->execute(); $this->exceptionTables[] = $exceptionTable; } diff --git a/src/Kernel/Attributes/LineNumberTableAttribute.php b/src/Kernel/Attributes/LineNumberTableAttribute.php index c0fe5bff..f1e70c8f 100644 --- a/src/Kernel/Attributes/LineNumberTableAttribute.php +++ b/src/Kernel/Attributes/LineNumberTableAttribute.php @@ -20,9 +20,7 @@ public function execute(): void $lineNumberTable = new \PHPJava\Kernel\Structures\_LineNumberTable($this->reader); $lineNumberTable->setConstantPool($this->getConstantPool()); $lineNumberTable->setDebugTool($this->getDebugTool()); - $lineNumberTable->setStartPc($this->readUnsignedShort()) - ->setLineNumber($this->readUnsignedShort()) - ->execute(); + $lineNumberTable->execute(); $this->lineNumberTables[] = $lineNumberTable; } } diff --git a/src/Kernel/Structures/_ExceptionTable.php b/src/Kernel/Structures/_ExceptionTable.php index 669a6848..3191308d 100644 --- a/src/Kernel/Structures/_ExceptionTable.php +++ b/src/Kernel/Structures/_ExceptionTable.php @@ -17,30 +17,10 @@ class _ExceptionTable implements StructureInterface public function execute(): void { - } - - public function setStartPc($startPc) - { - $this->startPc = $startPc; - return $this; - } - - public function setEndPc($endPc) - { - $this->endPc = $endPc; - return $this; - } - - public function setHandlerPc($handlerPc) - { - $this->handlerPc = $handlerPc; - return $this; - } - - public function setCatchType($catchType) - { - $this->catchType = $catchType; - return $this; + $this->startPc = $this->readUnsignedShort(); + $this->endPc = $this->readUnsignedShort(); + $this->handlerPc = $this->readUnsignedShort(); + $this->catchType = $this->readUnsignedShort(); } public function getStartPc() diff --git a/src/Kernel/Structures/_LineNumberTable.php b/src/Kernel/Structures/_LineNumberTable.php index 9f46b105..abe030a8 100644 --- a/src/Kernel/Structures/_LineNumberTable.php +++ b/src/Kernel/Structures/_LineNumberTable.php @@ -15,6 +15,8 @@ class _LineNumberTable implements StructureInterface public function execute(): void { + $this->startPc = $this->readUnsignedShort(); + $this->lineNumber = $this->readUnsignedShort(); } public function setStartPc($startPc) From 976f7ad0e82e46dbdf065839e6836980dac893fc Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 15:42:39 +0900 Subject: [PATCH 7/8] Remove unnecessary setter method --- src/Kernel/Structures/_LineNumberTable.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Kernel/Structures/_LineNumberTable.php b/src/Kernel/Structures/_LineNumberTable.php index abe030a8..cbd4c1c2 100644 --- a/src/Kernel/Structures/_LineNumberTable.php +++ b/src/Kernel/Structures/_LineNumberTable.php @@ -19,20 +19,11 @@ public function execute(): void $this->lineNumber = $this->readUnsignedShort(); } - public function setStartPc($startPc) - { - $this->startPc = $startPc; - return $this; - } - public function setLineNumber($lineNumber) - { - $this->lineNumber = $lineNumber; - return $this; - } public function getStartPc() { return $this->startPc; } + public function getLineNumber() { return $this->lineNumber; From 9dbf9383ab9116dd6bd7c16ba0fe20c691de6163 Mon Sep 17 00:00:00 2001 From: memory-agape Date: Tue, 30 Apr 2019 15:56:39 +0900 Subject: [PATCH 8/8] Add filter to load an atribution for saving memories --- src/Core/JVM/Parameters/Runtime.php | 6 ++++++ src/Kernel/Attributes/AttributeInfo.php | 11 +++++++++++ src/Kernel/Structures/_LineNumberTable.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Core/JVM/Parameters/Runtime.php b/src/Core/JVM/Parameters/Runtime.php index a5f61fac..e5be9951 100644 --- a/src/Core/JVM/Parameters/Runtime.php +++ b/src/Core/JVM/Parameters/Runtime.php @@ -21,6 +21,12 @@ final class Runtime const LOG_PATH = 'php://stderr'; const LOG_LEVEL = Logger::EMERGENCY; + const LOAD_ATTRIBUTES = [ + 'Code', + 'Exceptions', + 'SourceFile', + ]; + const PHP_PACKAGES_MAPS = [ 'String' => '_String', 'Object' => '_Object', diff --git a/src/Kernel/Attributes/AttributeInfo.php b/src/Kernel/Attributes/AttributeInfo.php index 84313d7e..d28040e7 100644 --- a/src/Kernel/Attributes/AttributeInfo.php +++ b/src/Kernel/Attributes/AttributeInfo.php @@ -1,6 +1,8 @@ attributeNameIndex = $this->readUnsignedShort(); $this->attributeLength = $this->readUnsignedInt(); $cpInfo = $this->getConstantPool(); $currentOffset = $this->getOffset(); $attributeName = $cpInfo[$this->attributeNameIndex]->getString(); + + if ($loadAttributes !== null && !in_array($attributeName, $loadAttributes, true)) { + $this->read($this->attributeLength); + $this->getDebugTool()->getLogger()->debug('Skip to load an attribute: ' . $attributeName); + return; + } + $classAttributeName = '\\PHPJava\\Kernel\\Attributes\\' . $attributeName . 'Attribute'; $this->getDebugTool()->getLogger()->debug('Load an attribute: ' . $attributeName); $this->attributeData = new $classAttributeName($this->reader); diff --git a/src/Kernel/Structures/_LineNumberTable.php b/src/Kernel/Structures/_LineNumberTable.php index cbd4c1c2..27b300a5 100644 --- a/src/Kernel/Structures/_LineNumberTable.php +++ b/src/Kernel/Structures/_LineNumberTable.php @@ -23,7 +23,7 @@ public function getStartPc() { return $this->startPc; } - + public function getLineNumber() { return $this->lineNumber;