1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-26 07:02:12 +03:00

Amend af784385b4: Avoid vtable overhead

When neither MSAN nor Valgrind are enabled, declare
Field::mark_unused_memory_as_defined() as an empty inline function,
instead of declaring it as a virtual function.
This commit is contained in:
Marko Mäkelä
2020-05-15 17:09:20 +03:00
parent 1cac6d4828
commit ff66d65a09
3 changed files with 16 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010, 2019, MariaDB Corporation. /* Copyright (C) 2010, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -32,6 +32,7 @@
#if defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind) #if defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
# include <valgrind/memcheck.h> # include <valgrind/memcheck.h>
# define HAVE_valgrind_or_MSAN
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len) # define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
# define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len) # define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len)
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len) # define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
@ -50,6 +51,7 @@ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */
# define REDZONE_SIZE 8 # define REDZONE_SIZE 8
#elif __has_feature(memory_sanitizer) #elif __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h> # include <sanitizer/msan_interface.h>
# define HAVE_valgrind_or_MSAN
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len) # define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len) # define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
# define MEM_NOACCESS(a,len) ((void) 0) # define MEM_NOACCESS(a,len) ((void) 0)

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2000, 2017, Oracle and/or its affiliates. Copyright (c) 2000, 2017, Oracle and/or its affiliates.
Copyright (c) 2008, 2017, MariaDB Copyright (c) 2008, 2020, MariaDB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -7772,11 +7772,14 @@ my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
} }
#ifdef HAVE_valgrind_or_MSAN
void Field_varstring::mark_unused_memory_as_defined() void Field_varstring::mark_unused_memory_as_defined()
{ {
uint used_length __attribute__((unused)) = get_length(); uint used_length= get_length();
MEM_MAKE_DEFINED(get_data() + used_length, field_length - used_length); MEM_MAKE_DEFINED(get_data() + used_length, field_length - used_length);
} }
#endif
int Field_varstring::cmp_max(const uchar *a_ptr, const uchar *b_ptr, int Field_varstring::cmp_max(const uchar *a_ptr, const uchar *b_ptr,

View File

@ -1,7 +1,7 @@
#ifndef FIELD_INCLUDED #ifndef FIELD_INCLUDED
#define FIELD_INCLUDED #define FIELD_INCLUDED
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. /* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
Copyright (c) 2008, 2017, MariaDB Corporation. Copyright (c) 2008, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -850,13 +850,17 @@ public:
enum_check_fields check_level); enum_check_fields check_level);
int store(const LEX_STRING *ls, CHARSET_INFO *cs) int store(const LEX_STRING *ls, CHARSET_INFO *cs)
{ return store(ls->str, (uint32) ls->length, cs); } { return store(ls->str, (uint32) ls->length, cs); }
/* #ifdef HAVE_valgrind_or_MSAN
/**
Mark unused memory in the field as defined. Mainly used to ensure Mark unused memory in the field as defined. Mainly used to ensure
that if we write full field to disk (for example in that if we write full field to disk (for example in
Count_distinct_field::add(), we don't write unitalized data to Count_distinct_field::add(), we don't write unitalized data to
disk which would confuse valgrind or MSAN. disk which would confuse valgrind or MSAN.
*/ */
virtual void mark_unused_memory_as_defined() {} virtual void mark_unused_memory_as_defined() {}
#else
void mark_unused_memory_as_defined() {}
#endif
virtual double val_real(void)=0; virtual double val_real(void)=0;
virtual longlong val_int(void)=0; virtual longlong val_int(void)=0;
@ -3250,7 +3254,9 @@ public:
int store(const char *to,uint length,CHARSET_INFO *charset); int store(const char *to,uint length,CHARSET_INFO *charset);
int store(longlong nr, bool unsigned_val); int store(longlong nr, bool unsigned_val);
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */ int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
#ifdef HAVE_valgrind_or_MSAN
void mark_unused_memory_as_defined(); void mark_unused_memory_as_defined();
#endif /* HAVE_valgrind_or_MSAN */
double val_real(void); double val_real(void);
longlong val_int(void); longlong val_int(void);
String *val_str(String*,String *); String *val_str(String*,String *);