1 // Copyright 2021 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 import java.util.ArrayList; 19 import java.util.Arrays; 20 21 public class MockCoverageMap { 22 public static final int SIZE = 65536; 23 public static final ByteBuffer mem = ByteBuffer.allocate(SIZE); 24 public static int prev_location = 0; // is used in byte code directly 25 26 private static final ByteBuffer previous_mem = ByteBuffer.allocate(SIZE); 27 public static ArrayList<Integer> locations = new ArrayList<>(); 28 updated()29 public static void updated() { 30 int updated_pos = -1; 31 for (int i = 0; i < SIZE; i++) { 32 if (previous_mem.get(i) != mem.get(i)) { 33 updated_pos = i; 34 } 35 } 36 locations.add(updated_pos); 37 System.arraycopy(mem.array(), 0, previous_mem.array(), 0, SIZE); 38 } 39 clear()40 public static void clear() { 41 Arrays.fill(mem.array(), (byte) 0); 42 Arrays.fill(previous_mem.array(), (byte) 0); 43 locations.clear(); 44 } 45 } 46