1 // Copyright 2022 Code Intelligence GmbH
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.code_intelligence.jazzer.instrumentor;
16 
17 import java.nio.ByteBuffer;
18 
19 public final class DirectByteBuffer2CoverageMap {
20   // The current target, JsonSanitizer, uses less than 2048 coverage counters.
21   private static final int NUM_COUNTERS = 4096;
22   public static final ByteBuffer counters = ByteBuffer.allocateDirect(NUM_COUNTERS);
23 
enlargeIfNeeded(int nextId)24   public static void enlargeIfNeeded(int nextId) {
25     // Statically sized counters buffer.
26   }
27 
recordCoverage(final int id)28   public static void recordCoverage(final int id) {
29     final byte counter = counters.get(id);
30     counters.put(id, (byte) (counter == -1 ? 1 : counter + 1));
31   }
32 }
33