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
2 changes: 1 addition & 1 deletion classparser/jdk_constructor_code_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestGenerateJDKConstructorCodeArchive(t *testing.T) {
Classes map[string]json.RawMessage
}
}
if err = json.Unmarshal(jdkInvocationCatalogJSON, &declared); err != nil {
if err = decodeJDKInvocationCatalog(&declared); err != nil {
t.Fatal(err)
}
expected := map[int]string{}
Expand Down
5 changes: 2 additions & 3 deletions classparser/jdk_constructor_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package javaclassparser

import (
"crypto/sha256"
"encoding/json"
"fmt"
"sort"
"testing"
Expand All @@ -26,7 +25,7 @@ func TestAdversarialPlatformInterfaceDeclarationsUsePinnedOriginalFlags(t *testi
}
}
}
if err := json.Unmarshal(jdkInvocationCatalogJSON, &catalog); err != nil {
if err := decodeJDKInvocationCatalog(&catalog); err != nil {
t.Fatal(err)
}
for _, profile := range catalog.Profiles {
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestAdversarialPlatformConstructorCodeIdentityAndEffectProof(t *testing.T)
References map[string]struct{ Archive, SHA256 string } `json:"reference_provenance"`
}
}
if err := json.Unmarshal(jdkInvocationCatalogJSON, &declared); err != nil {
if err := decodeJDKInvocationCatalog(&declared); err != nil {
t.Fatal(err)
}
for _, profile := range declared.Profiles {
Expand Down
8 changes: 1 addition & 7 deletions classparser/jdk_metadata_catalog.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package javaclassparser

import (
_ "embed"
"encoding/json"
"sync"

"github.com/yaklang/javajive/classparser/decompiler/core/callbinding"
Expand All @@ -11,10 +9,6 @@ import (
// These are full method tables extracted from specific trusted JDK8/9/11/16/17/21
// classfiles, not guessed overload-name uniqueness rules. See the adjacent
// provenance document and generator. No installed JDK is consulted at runtime.
//
//go:embed jdk_metadata_catalog.json
var jdkInvocationCatalogJSON []byte

type jdkCatalogProvenance struct {
Archive string `json:"archive"`
SHA256 string `json:"sha256"`
Expand Down Expand Up @@ -48,7 +42,7 @@ func loadJDKInvocationCatalog() {
ReferenceParents map[string][]string `json:"reference_hierarchy"`
} `json:"profiles"`
}
if json.Unmarshal(jdkInvocationCatalogJSON, &document) != nil || document.Schema != 3 {
if decodeJDKInvocationCatalog(&document) != nil || document.Schema != 3 {
return
}
profiles := make(map[int]map[string]callbinding.Class)
Expand Down
Binary file added classparser/jdk_metadata_catalog.json.zst
Binary file not shown.
8 changes: 8 additions & 0 deletions classparser/jdk_metadata_catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ python3 classparser/jdk_metadata_catalog_generate.py \
--jdk8 /path/to/jdk8 --jdk9 /path/to/jdk9 --jdk11 /path/to/jdk11 \
--jdk16 /path/to/jdk16 --jdk17 /path/to/jdk17 --jdk21 /path/to/jdk21 \
--out classparser/jdk_metadata_catalog.json
go generate ./classparser
```

The reviewed JSON remains the source of truth. Applications embed only
`jdk_metadata_catalog.json.zst`; the catalog is decompressed on its first
required lookup, within the existing one-time loader. The constructor classfile
ZIP and all exact-profile/provenance checks remain unchanged. The required
corpus tests compare decompressed bytes with the JSON source so regeneration
cannot silently omit a catalog update.

## Evidence and limits

Before this change, the unchanged `TestT22_C06_noRegression` rejected LongTest
Expand Down
31 changes: 31 additions & 0 deletions classparser/jdk_metadata_catalog_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package javaclassparser

import (
_ "embed"
"encoding/json"

"github.com/klauspost/compress/zstd"
)

// Keep the reviewed JSON source for regeneration and provenance checks. Only
// its compressed representation is linked into applications.
//
//go:generate go run ../tools/compressjdk -input jdk_metadata_catalog.json
//go:embed jdk_metadata_catalog.json.zst
var jdkInvocationCatalogZstd []byte

// The production caller runs this inside loadJDKInvocationCatalog's sync.Once.
// Neither package initialization nor unrelated class lookups decompress the
// catalog, and the temporary JSON buffer is released after parsing.
func decodeJDKInvocationCatalog(target any) error {
decoder, err := zstd.NewReader(nil, zstd.WithDecoderConcurrency(1), zstd.WithDecoderLowmem(true))
if err != nil {
return err
}
defer decoder.Close()
raw, err := decoder.DecodeAll(jdkInvocationCatalogZstd, nil)
if err != nil {
return err
}
return json.Unmarshal(raw, target)
}
28 changes: 28 additions & 0 deletions classparser/jdk_metadata_catalog_data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package javaclassparser

import (
"bytes"
"os"
"testing"

"github.com/klauspost/compress/zstd"
)

func TestJDKCompressedCatalogMatchesSource(t *testing.T) {
want, err := os.ReadFile("jdk_metadata_catalog.json")
if err != nil {
t.Fatal(err)
}
decoder, err := zstd.NewReader(nil, zstd.WithDecoderConcurrency(1))
if err != nil {
t.Fatal(err)
}
defer decoder.Close()
got, err := decoder.DecodeAll(jdkInvocationCatalogZstd, nil)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, want) {
t.Fatal("embedded JDK catalog differs from its reviewed source; run go generate ./classparser")
}
}
7 changes: 3 additions & 4 deletions classparser/jdk_metadata_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package javaclassparser

import (
"encoding/hex"
"encoding/json"
"reflect"
"sync"
"testing"
Expand Down Expand Up @@ -40,7 +39,7 @@ func TestJDKInvocationCatalogCompleteProfiles(t *testing.T) {
} `json:"provenance"`
} `json:"profiles"`
}
if err := json.Unmarshal(jdkInvocationCatalogJSON, &document); err != nil {
if err := decodeJDKInvocationCatalog(&document); err != nil {
t.Fatal(err)
}
if len(document.Profiles) != 6 {
Expand Down Expand Up @@ -177,7 +176,7 @@ func TestJDKCatalogModularNamespaceAndCheckedDeclarations(t *testing.T) {
} `json:"provenance"`
} `json:"profiles"`
}
if err := json.Unmarshal(jdkInvocationCatalogJSON, &document); err != nil {
if err := decodeJDKInvocationCatalog(&document); err != nil {
t.Fatal(err)
}
for _, profile := range document.Profiles {
Expand Down Expand Up @@ -407,7 +406,7 @@ func TestInvocationMetadataReferenceCatalogRequiresOriginalClosedProfilesAndNeve
} `json:"reference_provenance"`
} `json:"profiles"`
}
if e := json.Unmarshal(jdkInvocationCatalogJSON, &document); e != nil {
if e := decodeJDKInvocationCatalog(&document); e != nil {
t.Fatal(e)
}
if document.Schema != 3 || len(document.Profiles) != 6 {
Expand Down
3 changes: 1 addition & 2 deletions classparser/jdk_throwable_hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package javaclassparser

import (
"encoding/hex"
"encoding/json"
"github.com/yaklang/javajive/classparser/decompiler/core/callbinding"
"testing"
)
Expand All @@ -18,7 +17,7 @@ func TestJDKThrowableAncestryKeepsClassificationSeparateFromMembers(t *testing.T
} `json:"throwable_provenance"`
} `json:"profiles"`
}
if err := json.Unmarshal(jdkInvocationCatalogJSON, &document); err != nil {
if err := decodeJDKInvocationCatalog(&document); err != nil {
t.Fatal(err)
}
for _, profile := range document.Profiles {
Expand Down
3 changes: 1 addition & 2 deletions classparser/native_platform_indexed_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package javaclassparser

import (
"crypto/sha256"
"encoding/json"
"fmt"
"testing"
)
Expand All @@ -17,7 +16,7 @@ func TestAdversarialPlatformIndexedDeclarationsRetainOriginalBytecode(t *testing
Provenance map[string]struct{ Archive, SHA256 string }
}
}
if err := json.Unmarshal(jdkInvocationCatalogJSON, &catalog); err != nil {
if err := decodeJDKInvocationCatalog(&catalog); err != nil {
t.Fatal(err)
}
for _, profile := range catalog.Profiles {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.0
require (
github.com/go-viper/mapstructure/v2 v2.4.0
github.com/gobwas/glob v0.2.3
github.com/klauspost/compress v1.17.9
github.com/samber/lo v1.38.1
github.com/segmentio/ksuid v1.0.4
github.com/stretchr/testify v1.11.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9L
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
Expand Down
2 changes: 1 addition & 1 deletion javajive.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
)

// Version is the javajive library/CLI version.
const Version = "0.7.0"
const Version = "0.8.0"

// ---------------------------------------------------------------------------
// Re-exported types
Expand Down
42 changes: 42 additions & 0 deletions tools/compressjdk/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Command compressjdk deterministically compresses the reviewed JDK catalog.
package main

import (
"flag"
"fmt"
"os"

"github.com/klauspost/compress/zstd"
)

func main() {
input := flag.String("input", "", "reviewed JDK catalog JSON; output is <input>.zst")
flag.Parse()
if *input == "" || flag.NArg() != 0 {
fmt.Fprintln(os.Stderr, "usage: compressjdk -input jdk_metadata_catalog.json")
os.Exit(2)
}
if err := compress(*input); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func compress(input string) error {
raw, err := os.ReadFile(input)
if err != nil {
return err
}
encoder, err := zstd.NewWriter(nil,
zstd.WithEncoderLevel(zstd.SpeedBestCompression),
zstd.WithEncoderConcurrency(1),
zstd.WithWindowSize(8<<20),
zstd.WithEncoderCRC(true),
)
if err != nil {
return err
}
defer encoder.Close()
compressed := encoder.EncodeAll(raw, nil)
return os.WriteFile(input+".zst", compressed, 0644)
}
2 changes: 1 addition & 1 deletion tools/requiredci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var requiredSuites = []suite{
{Group: "corpus", Package: "./classparser/jarwar", Tests: 18, TestHash: "b1195066bc29f6a35391695fb815b4eef9eb42a55ef53f7ba9786375a27afc25"},
{Group: "corpus", Package: "./classparser/decompiler/jar", Tests: 1, TestHash: "e84c19ac824483c172a763d735732079fb808d6dd0153c53e573b18513d23553"},
{Group: "corpus", Package: "./jimage", Tests: 16, TestHash: "f68b01a6c2a476c2a5921fc30f5ab3a6c0b700fe04748ac1e1d5d9573e283df8", Exclude: []string{"TestJLinkBigEndianImage", "TestJLinkCompactCPImage", "TestOpenJDKImage"}},
{Group: "corpus", Package: "./classparser", Tests: 4176, TestHash: "1920a1d4ab6a93c33d503eaa29b825151063d1d728b63ef7bdaf687a53802c92", Include: []string{"TestDumpMethodsPointerFastPathKeepsDescriptor", "TestJoinRuleChainExactOutput", "TestSourceRewritePrecisionOuterGateSemantics", "TestRewriteSchedulerOrderMatchesDumperCallSites", "TestRewriteSchedulerPositiveAndNearMissExactOutput", "TestRewriteSchedulerPreservesRecordsDiagnosticsAndHashes", "TestRewriteSchedulerDecompileEquivalence", "TestJDKObjectMetadataMatchesCatalog", "TestAdversarialPlatformConstructorCodeIdentityAndEffectProof", "TestLoopAnalysisCacheMatchesUncachedDecompile", "FuzzDecompileWithLimitsNeverPanics"}},
{Group: "corpus", Package: "./classparser", Tests: 4177, TestHash: "7a0f8f15a3694fc97e99ed38d37f3f621481161e23ea97755762cedf09a847bc", Include: []string{"TestDumpMethodsPointerFastPathKeepsDescriptor", "TestJoinRuleChainExactOutput", "TestSourceRewritePrecisionOuterGateSemantics", "TestRewriteSchedulerOrderMatchesDumperCallSites", "TestRewriteSchedulerPositiveAndNearMissExactOutput", "TestRewriteSchedulerPreservesRecordsDiagnosticsAndHashes", "TestRewriteSchedulerDecompileEquivalence", "TestJDKObjectMetadataMatchesCatalog", "TestJDKCompressedCatalogMatchesSource", "TestAdversarialPlatformConstructorCodeIdentityAndEffectProof", "TestLoopAnalysisCacheMatchesUncachedDecompile", "FuzzDecompileWithLimitsNeverPanics"}},

{Group: "algorithm", Package: "./classparser/decompiler/core", Tests: 413, TestHash: "cf788257ac2b6de14e9ba85f18a6fd70fcdc9f7f31d85b6538bb8b1344fff93b"},
{Group: "algorithm", Package: "./classparser/decompiler/core/callbinding", Tests: 17, TestHash: "e7eafd33ec36c2219f362b5c45872f126dde5a81dab84d931023fd1abc1836cc"},
Expand Down
Loading