Skip to content

Commit 9dbf938

Browse files
committed
Add filter to load an atribution for saving memories
1 parent 976f7ad commit 9dbf938

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Core/JVM/Parameters/Runtime.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ final class Runtime
2121
const LOG_PATH = 'php://stderr';
2222
const LOG_LEVEL = Logger::EMERGENCY;
2323

24+
const LOAD_ATTRIBUTES = [
25+
'Code',
26+
'Exceptions',
27+
'SourceFile',
28+
];
29+
2430
const PHP_PACKAGES_MAPS = [
2531
'String' => '_String',
2632
'Object' => '_Object',

src/Kernel/Attributes/AttributeInfo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace PHPJava\Kernel\Attributes;
33

4+
use PHPJava\Core\JVM\Parameters\GlobalOptions;
5+
use PHPJava\Core\JVM\Parameters\Runtime;
46
use PHPJava\Exceptions\NotImplementedException;
57
use PHPJava\Exceptions\ValidatorException;
68
use PHPJava\Kernel\Structures\_Methodref;
@@ -19,12 +21,21 @@ final class AttributeInfo implements AttributeInterface
1921

2022
public function execute(): void
2123
{
24+
$loadAttributes = GlobalOptions::get('load_attributes') ?? Runtime::LOAD_ATTRIBUTES;
25+
2226
$this->attributeNameIndex = $this->readUnsignedShort();
2327
$this->attributeLength = $this->readUnsignedInt();
2428
$cpInfo = $this->getConstantPool();
2529
$currentOffset = $this->getOffset();
2630

2731
$attributeName = $cpInfo[$this->attributeNameIndex]->getString();
32+
33+
if ($loadAttributes !== null && !in_array($attributeName, $loadAttributes, true)) {
34+
$this->read($this->attributeLength);
35+
$this->getDebugTool()->getLogger()->debug('Skip to load an attribute: ' . $attributeName);
36+
return;
37+
}
38+
2839
$classAttributeName = '\\PHPJava\\Kernel\\Attributes\\' . $attributeName . 'Attribute';
2940
$this->getDebugTool()->getLogger()->debug('Load an attribute: ' . $attributeName);
3041
$this->attributeData = new $classAttributeName($this->reader);

src/Kernel/Structures/_LineNumberTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getStartPc()
2323
{
2424
return $this->startPc;
2525
}
26-
26+
2727
public function getLineNumber()
2828
{
2929
return $this->lineNumber;

0 commit comments

Comments
 (0)