Parma Polyhedra Library requirements
Java boundary contracts

Java boundary contracts

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-001688
Java integral coefficient exchange

Coefficient shall hold the integer supplied through its integer, decimal string or BigInteger constructor, and copying and getBigInteger shall preserve that value. toString shall return its decimal representation. bits shall return the configured native coefficient width, or zero for unbounded native coefficients.

For a valid coefficient representable by the native coefficient type, conversion through a supported native operation and back to Java shall preserve its integral value, including its sign and zero. Conversion shall use the full decimal value, without narrowing it through int or long. In an unbounded configuration this includes integers outside both primitive ranges. Native arithmetic retains its configured range and policy; Java's BigInteger does not extend that range. Checked out-of-range conversion shall use 🔗 3. Java native failure and pending-exception protocol.

Exchanging the decimal integer avoids truncating an exact coefficient to a host primitive width.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Round-trip zero, signed small values, configured endpoints and, when unbounded, values larger than 64 bits through a native constant objective. Check checked-range failures separately from valid native arithmetic.

interfaces/Java/parma_polyhedra_library/Coefficient.java; interfaces/Java/jni/ppl_java_common_inlines.hh; interfaces/Java/tests/Native_Handle_test1.java.

Java
Public

Package parma_polyhedra_library.

Coefficient(int i);
Coefficient(long l);
Coefficient(java.math.BigInteger bi);
Coefficient(String s);
Coefficient(Coefficient c);
java.math.BigInteger getBigInteger();
String toString();
static native int bits();

Native exchange occurs in coefficient-bearing expressions, constraints, generators and solver queries. String input shall be a valid decimal integer; BigInteger and copy inputs shall be non-null.

SW_SPEC
2
PPL-SPEC-001689
Java library initialization and finalization

After loading the configured JNI library, initialize_library shall establish native library state and the Java class cache before supported operations. finalize_library shall release that cache, the calling thread's variable stringifier and deterministic-timeout state, and the native initialization owner. A later initialization shall establish a new valid period of use.

Clients shall release owned objects, cease using borrowed views, and end worker thread participation before finalization. Requests shall alternate valid initialization and finalization; duplicate library requests are outside this protocol. Participating workers shall obey 🔗 6. Thread entry and shared-facility use.

JNI loading, Java class caching and native initialization have distinct resource lifetimes.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Load the JNI library and complete two initialize/use/release/finalize cycles, checking native coefficient and solver operations during each cycle. Inspect class-reference and thread-resource cleanup.

interfaces/Java/parma_polyhedra_library/Parma_Polyhedra_Library.java; interfaces/Java/jni/ppl_java_globals.cc; interfaces/Java/jni/ppl_java_common_inlines.hh; interfaces/Java/tests/Native_Handle_test1.java.

Java
Public

Package parma_polyhedra_library, class Parma_Polyhedra_Library.

public static native void initialize_library();
public static native void finalize_library();

The JNI library shall first be loaded using the host's native-library loading mechanism. The initializing thread owns the library lifecycle.

SW_SPEC
3
PPL-SPEC-001690

Supported JNI numerical entry points shall contain native exceptions. Native invalid_argument, domain_error, length_error, logic_error and overflow_error shall become the corresponding Java binding exceptions. Supported native interruption shall become Timeout_Exception. Allocation failure shall become a Java exception describing out-of-memory failure; other standard and unexpected native exceptions shall become RuntimeException with a diagnostic.

A Java exception already pending after a host callback or object creation shall be returned to Java without replacement by a translated native exception. Argument-conversion callbacks shall complete before native access to a receiver that they may release; released receivers shall be rejected. Host-runtime termination and undefined behavior are outside the failure model.

A host callback failure and a false numerical result must remain distinguishable, and a pending exception carries the original Java cause.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Check invalid dimensions, released receivers, copy and index admission, release during callbacks, and identity of a callback-thrown exception. Check checked conversion overflow in bounded checked configurations. Inspect every native failure category and failed JNI allocation path; use controlled injection for allocation and otherwise inaccessible failures.

interfaces/Java/jni/ppl_java_common_defs.hh; interfaces/Java/jni/ppl_java_common.cc; interfaces/Java/jni/ppl_java_globals.cc; interfaces/Java/tests/Native_Handle_test1.java.

Java
Public

Package parma_polyhedra_library: native methods of numerical wrappers and Parma_Polyhedra_Library. The reported exception classes are Invalid_Argument_Exception, Domain_Error_Exception, Length_Error_Exception, Logic_Error_Exception, Overflow_Error_Exception, Timeout_Exception and java.lang.RuntimeException. A pending host exception retains its object identity. Operations require the lifecycle of 🔗 2. Java library initialization and finalization.

SW_SPEC
4
PPL-SPEC-001691
PPL-SPEC-001691
Java owned wrappers and borrowed views

An owned numerical wrapper shall release its native allocation through explicit free or managed finalization, without a later cleanup deleting that allocation again. Copy construction shall produce an independent native object. Borrowed-wrapper cleanup shall not delete the underlying owned object.

Factories shall bind view owners before allocating native cursor storage, or retain native results in an exception-safe owner until all fallible publication steps complete. Failed JNI allocation or native computation shall leave no stranded native result. Replacing a ranking-function output shall release its previous value while preserving ownership of the output wrapper.

MIP and partial-function wrappers shall reject native access after release. Powerset cursors and disjuncts shall retain their owner, validate its current generation, and reject stale use; disjuncts shall be read-only and copying one shall produce an independent writable object. Cursor operations shall reject boundary and foreign-owner misuse. Mutating or potentially normalizing a powerset shall invalidate its dependent views except for the documented cursor returned by single removal. Stable metadata queries shall preserve them.

PIP tree views shall retain their problem owner and reject access after owner release or a mutation invalidating the captured tree generation. View cleanup shall leave independently owned problems usable. Managed cleanup timing is controlled by the JVM. Clients shall obey 🔗 2. Java library initialization and finalization and the operation-specific borrowing and synchronization prerequisites.

Host reachability and native ownership differ; generation checks prevent views from referring to replaced native storage.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Check both release/finalization orders, repeated cleanup, independent copies, released access and release during conversion. Check powerset owner retention, stale and read-only views, cursor bounds and owner checks; check PIP owner retention and mutation invalidation. Inspect concrete generated finalizers and use allocation-sensitive checks for owned cleanup. Inject JNI object/token and native allocation failures into cursor, partition and ranking-output factories.

interfaces/Java/parma_polyhedra_library/PPL_Object.java; interfaces/Java/jni/ppl_interface_generator_java_classes_cc_code.m4; interfaces/Java/jni/ppl_java_globals.cc; interfaces/Java/tests/Native_Handle_test1.java; interfaces/Java/tests/Powerset_Lifetime_test1.java; interfaces/Java/tests/PIP_Lifetime_test1.java; interfaces/Java/tests/Native_Publication_test1.java; interfaces/Java/tests/jni_native_publication_test.cc.

Java
Public

Package parma_polyhedra_library: PPL_Object subclasses, owned numerical constructors and copy constructors, free and managed finalize methods; PIP solution-tree accessors; configured powerset begin_iterator, end_iterator, iterator copying, traversal and get_disjunct methods. Released MIP/partial-function access and invalid borrowed access shall report Invalid_Argument_Exception. A borrowed view is not an independently owned native allocation.

SW_SPEC
5
PPL-SPEC-001707
PPL-SPEC-001707
Scoped JNI modified UTF-8 character release

UTF_Chars_Lease shall adopt one non-null result of a successful GetStringUTFChars call. The JNI environment, Java string and character pointer shall identify that same acquisition, and shall remain valid on the acquiring thread until the lease is destroyed. The adopted acquisition shall have no other owner responsible for release.

Destruction shall call ReleaseStringUTFChars exactly once with the adopted environment, string and pointer, both at ordinary scope exit and during C++ exception unwinding. The lease shall neither copy the characters nor allocate storage. Copy construction and copy assignment shall be unavailable. Releasing the characters shall preserve any pending Java exception.

Coefficient import, Java-customized variable output and Java text wrapping shall adopt each successfully acquired character pointer before any subsequent throwing native operation. Coefficient import shall return the value parsed from the acquired decimal characters. The variable formatter shall retain the characters through output. Text wrapping shall release them before allocating the returned Java string. Failed acquisition shall not create a lease and shall retain the entry point's existing JNI failure behavior.

JNI character storage is not a C++ automatic object. A native conversion, allocation or output failure must still end its lifetime through the matching JNI release operation.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Count successful acquisitions and matching releases during normal coefficient conversion, malformed conversion, checked-coefficient overflow, failing public Variable output and injected allocation failure in public Java text wrapping. Each acquired pointer shall be released once. Check zero releases after failed acquisition or an earlier callback exception, unchanged successful values and text, callback exception identity, and release with a pending Java exception. Exercise the lease directly at ordinary exit and bad_alloc unwinding. Inspect all GetStringUTFChars sites and non-copyability.

interfaces/Java/jni/ppl_java_utf_chars.hh; interfaces/Java/jni/ppl_java_common_inlines.hh; interfaces/Java/jni/ppl_java_common.cc; interfaces/Java/jni/ppl_java_globals.cc; interfaces/Java/tests/JNI_UTF_Chars_test1.java; interfaces/Java/tests/jni_utf_chars_test.cc.

CPP
Internal

Namespace Parma_Polyhedra_Library::Interfaces::Java.

class UTF_Chars_Lease {
public:
  UTF_Chars_Lease(JNIEnv*, jstring, const char*) noexcept;
  ~UTF_Chars_Lease();
  UTF_Chars_Lease(const UTF_Chars_Lease&) = delete;
  UTF_Chars_Lease& operator=(const UTF_Chars_Lease&) = delete;
};

Integration points are build_cxx_coeff, Java_Variable_output_function and Java_parma_1polyhedra_1library_IO_wrap_1string. Ownership lasts until destruction; the acquired pointer shall not be used afterwards.

SW_SPEC
6
PPL-SPEC-001728
PPL-SPEC-001728
Java mathematical representations and operation options

For valid supported Java values, native exchange shall preserve variable indices, representable coefficients and the mathematical meaning of expression trees, constraints, congruences, generators, grid generators and artificial parameters. Expression sums, differences, integer products and negation shall retain their operands' meanings. Constraint direction, congruence modulus, generator kind and divisor, and artificial-parameter numerator and denominator shall be preserved. Coefficient exchange obeys 🔗 1. Java integral coefficient exchange. Native affine, constraint, congruence, generator and grid-generator meanings are specified by 🔗 1. Affine value, numerical prerequisites and shared zero, 🔗 1. Constraint relation meaning and numerical prerequisites, 🔗 1. Affine congruence meaning and valid numerical use, 🔗 1. Generator kinds and numerical prerequisites and 🔗 1. Grid-generator values and integer versus continuous displacement, respectively. Returned mathematical objects may be normalized and need not preserve the input expression-tree shape.

Conversion of a finite acyclic expression into native form shall preserve operator grouping and apply the configured coefficient rules at each node. This conversion and copying through built-in Java expression nodes shall use stack space independent of tree depth. Construction and cloning shall retain the documented ownership of copied operands.

System and variable-set conversion shall retain the represented collection; artificial-parameter sequences shall retain their order. Relation objects shall encode the native predicates (subsumption; disjointness, strict intersection, inclusion and saturation). Boxed primitives, Pair fields and By_Reference values shall preserve the values or object references assigned to them.

Named Java enumeration values for relation symbols, integer widths, representations and overflow policies, optimization modes, solver results and MIP/PIP control parameters shall denote the corresponding native choices. Choosing a complexity or overflow policy shall not strengthen the native operation's exactness guarantee. Nonnegative integral arguments converted to an unsigned native type shall be rejected if negative or outside that type's range; failures follow 🔗 3. Java native failure and pending-exception protocol. Native dimension and object validity preconditions remain applicable.

Java object layout, enum ordinals and container fields are representation details; native conversion must preserve their mathematical and option meanings.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Inspect each constructor/accessor correspondence, expression-node case, system iterator and enum switch against the Java definitions and native meanings. Check signed/unsigned range admission, affine constants, generator divisors, relation flags and container field positions. Use existing Java domain and solver scenarios as supporting runtime evidence, comparing normalization by mathematical meaning. Construct and copy mixed expression trees, check subtree independence and convert against an independently known affine result.

interfaces/Java/jni/ppl_java_common.cc; interfaces/Java/jni/ppl_java_common_defs.hh; interfaces/Java/jni/ppl_java_common_inlines.hh; interfaces/Java/tests/Linear_Expression_test1.java; interfaces/Java/parma_polyhedra_library.

Java
Public

Package parma_polyhedra_library: Variable, the Linear_Expression hierarchy, Constraint, Congruence, Generator, Grid_Generator, Artificial_Parameter, their system/sequence classes, Variables_Set, Poly_Gen_Relation, Poly_Con_Relation, the operation-option/result enums, Pair and By_Reference. Values must have the documented class, finite acyclic expression structure and supported enum membership; mathematical objects must satisfy their native constructor preconditions.

SW_SPEC
7
PPL-SPEC-001729
PPL-SPEC-001729
Java dimension limits and exact native counts

For an unsigned integral native type, java_dimension_limit shall return the smaller of the supplied native limit and the greatest Java long value. java_unsigned_value shall return the exact supplied count when representable by Java long and otherwise throw std::overflow_error. check_java_dimension_growth shall check the current dimension and both successive increments against that effective limit without unsigned wraparound. It shall throw std::length_error if the resulting dimension is inadmissible, before either increment is applied to the numerical object.

JNI count queries for PIP parameter dimensions, constraints and artificial parameters shall return the corresponding native cardinalities. They require valid problem/node handles; wrapper failures follow 🔗 3. Java native failure and pending-exception protocol. A constraint count already represented by a signed iterator difference shall be representable by Java long; other unsigned count conversion uses the checked conversion above.

Java uses a signed count type even when the native count type is unsigned; admission must precede mutation and must not narrow a value silently.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

Check unsigned types narrower than, equal to and wider than Java's positive range; zero, exact-limit and overflowing counts; and each increment at the remaining-capacity boundary. Confirm rejection precedes object mutation. Inspect all three JNI cardinality queries against their native collections.

interfaces/Java/jni/ppl_java_limits.hh; interfaces/Java/jni/ppl_java_globals.cc; interfaces/Java/tests/unsignedlimits1.cc.

CPP
Internal

Namespace Parma_Polyhedra_Library::Interfaces::Java:

template <typename Unsigned> jlong java_dimension_limit(Unsigned limit);
template <typename Unsigned> jlong java_unsigned_value(Unsigned value);
template <typename Unsigned>
void check_java_dimension_growth(Unsigned current, Unsigned first,
                                 Unsigned second, Unsigned limit);

Unsigned shall be an unsigned integral type. JNI queries implement PIP_Problem.number_of_parameter_space_dimensions, PIP_Problem.number_of_constraints and PIP_Tree_Node.number_of_artificials.

SW_SPEC
8
PPL-SPEC-001730
PPL-SPEC-001730
Native Java floating-point environment lifetime

When PPL_CAN_CONTROL_FPU is true, successful construction of Java_FPU_Guard shall save the calling thread's floating-point environment and establish the rounding required by PPL. Failure to save the environment shall throw std::runtime_error before changing the rounding direction. Destruction shall restore the saved environment on normal return and exception unwinding, subject to the host's successful floating-point environment operations. The guard shall be constructed after Java argument conversions that may execute host code and before the native floating-point numerical operation. The lifetime shall remain on the same thread. Copy construction and copy assignment shall be unavailable. When FPU control is unavailable the guard shall perform no FPU changes and shall not make unsupported floating-point operations valid.

The JVM may reset its floating-point state during callbacks, and native rounding must not leak into subsequent Java execution.

APPROVED
JAVA_INTERFACE
IF_JAVA
Test, Analysis, Inspection

For every available host rounding direction, verify upward native rounding, correct interval computation, and restoration after return and unwinding. On x86/SSE check restoration when x87 and SSE initially disagree. Inspect guard placement after conversion callbacks and before native numerical operations.

interfaces/Java/jni/ppl_java_rounding.hh; interfaces/Java/tests/jni_rounding1.cc; interfaces/Java/jni/ppl_interface_generator_java_classes_cc_code.m4.

CPP
Internal

Namespace Parma_Polyhedra_Library::Interfaces::Java:

class Java_FPU_Guard {
public:
  Java_FPU_Guard();
  ~Java_FPU_Guard();
  Java_FPU_Guard(const Java_FPU_Guard&) = delete;
  Java_FPU_Guard& operator=(const Java_FPU_Guard&) = delete;
};