public int remap(int var, int size) {
    if ((var & REMAP_FLAG) != 0) {
      return unmask(var);
    }

    int offset = var - argsSize;
    if (offset < 0) {
      // self projection for method arguments
      return var;
    }
    if (offset >= mapping.length) {
      mapping = Arrays.copyOf(mapping, Math.max(mapping.length * 2, offset + 1));
    }
    int mappedVar = mapping[offset];
    int unmasked = unmask(mappedVar);

    boolean isRemapped = ((mappedVar & REMAP_FLAG) != 0);
    if (size == 2) {
      if ((mappedVar & DOUBLE_SLOT_FLAG) == 0) {
        // no double slot mapping over an int slot;
        // must re-map unless the int slot is the last used one or there is a free double-ext slot
        isRemapped = false;
      }
    } else {
      // size == 1
      if ((mappedVar & DOUBLE_SLOT_FLAG_2) != 0) {
        // no mapping over a previously 2-slot value
        isRemapped = false;
      } else if ((mappedVar & DOUBLE_SLOT_FLAG) != 0) {
        // the previously second part of the double slot is free to reuse
        mapping[unmasked + 1] = (unmasked + 1) | REMAP_FLAG;
      }
    }
    if (!isRemapped) {
      mappedVar = remapVar(newVarIdxInternal(size), size);
      setMapping(offset, mappedVar, size);
    }

    unmasked = unmask(mappedVar);
    // adjust the mapping pointer if remapping with variable occupying 2 slots
    nextMappedVar = Math.max(unmasked + size, nextMappedVar);
    return unmasked;
  }
@Test
  public void remapOverflow() {
    assertEquals(
        0,
        instance.remap(
            16, 1)); // default mapping array size is 8 so going for double should trigger overflow
    // handling
  }