Skip to content

Commit 1f74cbe

Browse files
committed
Update
1 parent fa7a67d commit 1f74cbe

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

src/Core/JVM/Cache/Cache.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
class Cache
55
{
6-
private $items = [];
6+
private static $items = [];
77

8-
public function fetchOrPush(string $key, callable $pushFunction)
8+
public static function fetchOrPush(string $key, callable $pushFunction, ...$parameters)
99
{
10-
if (isset($this->items[$key])) {
11-
return $this->items[$key];
10+
if (isset(self::$items[$key])) {
11+
return self::$items[$key];
1212
}
13-
return $this->items[$key] = $pushFunction();
13+
return self::$items[$key] = $pushFunction(...$parameters);
1414
}
1515
}

src/Core/JVM/Cache/HeapCache.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Cache;
3+
4+
class HeapCache extends Cache
5+
{
6+
}

src/Core/JVM/Invoker/Invokable.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function ($item) {
229229
]
230230
)
231231
);
232-
$operationCache = new OperationCache();
232+
233233
while ($reader->getOffset() < $codeAttribute->getOpCodeLength()) {
234234
if (++$executedCounter > ($this->options['max_stack_exceeded'] ?? GlobalOptions::get('max_stack_exceeded') ?? Runtime::MAX_STACK_EXCEEDED)) {
235235
throw new RuntimeException(
@@ -296,23 +296,23 @@ function ($item) {
296296
/**
297297
* @var OperationInterface|Accumulator|ConstantPool $executor
298298
*/
299-
$executor = $operationCache->fetchOrPush(
299+
$executor = OperationCache::fetchOrPush(
300300
$fullName,
301-
function () use ($fullName) {
302-
return new $fullName();
301+
function () use ($fullName, &$currentConstantPool) {
302+
return (new $fullName())
303+
->setConstantPool($currentConstantPool);
303304
}
304305
);
305-
$executor = new $fullName();
306-
$executor->setConstantPool($currentConstantPool);
307-
$executor->setParameters(
308-
$method->getAttributes(),
309-
$this->javaClassInvoker,
310-
$reader,
311-
$localStorage,
312-
$stacks,
313-
$pointer
314-
);
315-
$returnValue = $executor->execute();
306+
$returnValue = $executor
307+
->setParameters(
308+
$method->getAttributes(),
309+
$this->javaClassInvoker,
310+
$reader,
311+
$localStorage,
312+
$stacks,
313+
$pointer
314+
)
315+
->execute();
316316

317317
$afterTrigger = $this->options['operations']['injections']['after'] ?? GlobalOptions::get('operations.injections.after');
318318
if (is_callable($afterTrigger)) {

src/Kernel/Core/Accumulator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public function setParameters(
3737
\PHPJava\Core\JVM\Stream\BinaryReader $reader,
3838
array &$localStorage,
3939
array &$stacks,
40-
int $pointer
40+
int &$pointer
4141
): self {
42-
$this->attributes = $attributes;
43-
$this->javaClassInvoker = $javaClassInvoker;
42+
$this->attributes = &$attributes;
43+
$this->javaClassInvoker = &$javaClassInvoker;
4444
$this->javaClass = $javaClassInvoker->getJavaClass();
4545
$this->options = $this->javaClass->getOptions();
46-
$this->reader = $reader;
46+
$this->reader = &$reader;
4747
$this->localStorage = &$localStorage;
4848
$this->stacks = &$stacks;
49-
$this->pointer = $pointer;
49+
$this->pointer = &$pointer;
5050
return $this;
5151
}
5252

src/Kernel/Types/Type.php

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

4+
use PHPJava\Core\JVM\Cache\HeapCache;
45
use PHPJava\Exceptions\TypeException;
56

67
class Type

0 commit comments

Comments
 (0)