diff --git a/src/hotspot/share/utilities/unsigned5.hpp b/src/hotspot/share/utilities/unsigned5.hpp index 8e3724a0012a6..1fc6aeaffb605 100644 --- a/src/hotspot/share/utilities/unsigned5.hpp +++ b/src/hotspot/share/utilities/unsigned5.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -280,6 +280,7 @@ class UNSIGNED5 : AllStatic { int len = next_length(); // 0 or length in [1..5] if (len == 0) break; _position += len; + ++actual; } return actual; } diff --git a/test/hotspot/gtest/utilities/test_unsigned5.cpp b/test/hotspot/gtest/utilities/test_unsigned5.cpp index f3859d0a750a5..d3288e1f8c7a0 100644 --- a/test/hotspot/gtest/utilities/test_unsigned5.cpp +++ b/test/hotspot/gtest/utilities/test_unsigned5.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -221,6 +221,46 @@ TEST_VM(unsigned5, reader) { ASSERT_EQ(x, y) << i; } ASSERT_TRUE(i < LEN); + + { // Begin try_skip() test. + i = 0; + int skipped = 0; + r1.set_position(0); + // Skip from beginning to ith position. + for (; i < LEN; i++) { + skipped = r1.try_skip(i); + ASSERT_EQ(i, skipped); + const int x = r1.next_uint(); + const int y = ints[i]; + ASSERT_EQ(x, y) << i; + r1.set_position(0); + } + // Perform incremental skips. + int skipped_total = 0; + while (true) { + const int skip = skipped_total % 9; + skipped = r1.try_skip(skip); + skipped_total += skipped; + if (skipped_total > LEN - 1) { + r1.set_position(0); + break; + } + ASSERT_EQ(skip, skipped); + const int x = r1.next_uint(); + const int y = ints[skipped_total]; + ASSERT_EQ(x, y) << skipped_total; + // Update skipped_total because reader + // moved one position when reading x. + ++skipped_total; + } + // Underflow. + skipped = r1.try_skip(-1); + ASSERT_EQ(0, skipped) << skipped; + // Overflow. + skipped = r1.try_skip(LEN + 1); + ASSERT_EQ(LEN, skipped) << skipped; + } // End try_skip() test. + // copy from reader to writer UNSIGNED5::Reader r3(buf); int array_limit = 1;