Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions src/Core/JVM/ActiveAttributes.php

This file was deleted.

29 changes: 0 additions & 29 deletions src/Core/JVM/ActiveInterface.php

This file was deleted.

61 changes: 61 additions & 0 deletions src/Core/JVM/AttributePool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace PHPJava\Core\JVM;

use PHPJava\Core\Stream\Reader\ReaderInterface;
use PHPJava\Exceptions\ReadOnlyException;
use PHPJava\Kernel\Attributes\AttributeInfo;
use PHPJava\Utilities\DebugTool;

class AttributePool implements \ArrayAccess, \Countable
{
private $entries = [];
private $reader;

public function __construct(
ReaderInterface $reader,
int $entries,
ConstantPool $constantPool,
DebugTool $debugTool
) {
$this->reader = $reader;
for ($i = 0; $i < $entries; $i++) {
// not implemented, read only
$entry = (new AttributeInfo($reader))
->setConstantPool($constantPool)
->setDebugTool($debugTool);
$entry->execute();

$this->entries[] = $entry;
}
}

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.');
}
}
7 changes: 6 additions & 1 deletion src/Core/JVM/ConstantPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
Expand Down
28 changes: 27 additions & 1 deletion src/Core/JVM/ActiveFields.php → src/Core/JVM/FieldPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.');
}
}
55 changes: 55 additions & 0 deletions src/Core/JVM/InterfacePool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace PHPJava\Core\JVM;

use PHPJava\Core\JavaClass;
use PHPJava\Core\Stream\Reader\ReaderInterface;
use PHPJava\Exceptions\ReadOnlyException;
use PHPJava\Utilities\DebugTool;

class InterfacePool implements \ArrayAccess, \Countable
{
private $entries = [];
private $reader;

public function __construct(
ReaderInterface $reader,
int $entries,
ConstantPool $constantPool,
DebugTool $debugTool
) {
$this->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.');
}
}
3 changes: 0 additions & 3 deletions src/Core/JVM/Invoker/Invokable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
28 changes: 27 additions & 1 deletion src/Core/JVM/ActiveMethods.php → src/Core/JVM/MethodPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.');
}
}
6 changes: 6 additions & 0 deletions src/Core/JVM/Parameters/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 5 additions & 9 deletions src/Core/JVM/Stream/BinaryReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Loading